Git Product home page Git Product logo

hackerrank-solutions's Introduction

hackerrank-solutions's People

Contributors

a-star0 avatar c650 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hackerrank-solutions's Issues

Issue for test case 7

Hey, this is perfect solution, but it seems like it is not passing test case number 7. Hope you resolve it out.
Anyways it is better solution.

issue with a test case

Hi, this is a brilliant solution but I was getting some difficulty while running a specific test case using your code.

Test case

5 3
10 20 30 40 50

I went through the code and came up with the new solution Please review my solution

#include
#include
#include

using namespace std;

int main(void) {
int n,d;
cin >> n >> d;

vector<int> days(n);
for (auto& e : days)
    cin >> e;

vector<size_t> freq(201);
size_t i = 0;
for (; i < d; ++i)
    ++freq[days[i]];
// till here we are doing

for (size_t j = 1; j < freq.size(); ++j)
    freq[j] += freq[j-1];

size_t cnt = 0;
double tmp;

size_t j;
while(i < n) {
    for (j = 0; j < freq.size() && freq[j] <= d/2; ++j);
    
    //cout<<"j="<<j<<" freq[j]="<<freq[j]<<"\n";
    //  freq[j] >= d/2
   if (freq[j-1] == d/2) {
        tmp = j;
        //cout<<"#temp="<<tmp<<" \n";
        if (d % 2 == 0) {
            for(int k=j-1;k>0;k--){
                if(freq[k]<d/2){
                    //cout<<"#freq[k]="<<freq[k]<<"\n";
                    tmp+=k+1;
                    break;
                }
            }
            tmp /= 2;
        }
    }

    else {
        tmp = j;
        if (d % 2 == 0) {
            tmp += freq[j-1] + 1 == freq[j] ? j-1 : j;
           tmp /= 2;
        }
    }

    tmp *= 2; 
    //cout<<"temp="<<tmp<<" ";

    cnt += days[i] >= tmp;

    for (j = days[i-d]; j < freq.size(); ++j)
        --freq[j];
    for (j = days[i]; j < freq.size(); ++j)
        ++freq[j];
    
    ++i;
}

cout << cnt << '\n';

return 0;

}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.