HackerRank Solutions by @c650Alpha (me)
c650 / hackerrank-solutions Goto Github PK
View Code? Open in Web Editor NEWrepository for the storage and display of solutions to various problems on HackerRank
License: MIT License
repository for the storage and display of solutions to various problems on HackerRank
License: MIT License
HackerRank Solutions by @c650Alpha (me)
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.
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;
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.