We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@raghav_prakash,
Every thing is fine in your code, except this portion of calculating count array
// subArrayAsList size is d(0<=d<=n) which leads to O(n*n).
for(int elem : subArrayAsList)
countArray[elem]++;
So do not create countArray every time.
create countArray[] of size 201 first time with give d for say 5
d1, d2, d3, d4, d5
from next iteration onwards use same countArray which is created earleir with d6 insertion and d1 removal.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Fraudulent Activity Notifications
You are viewing a single comment's thread. Return to all comments →
@raghav_prakash, Every thing is fine in your code, except this portion of calculating count array // subArrayAsList size is d(0<=d<=n) which leads to O(n*n). for(int elem : subArrayAsList)
countArray[elem]++;
So do not create countArray every time.
create countArray[] of size 201 first time with give d for say 5
d1, d2, d3, d4, d5
from next iteration onwards use same countArray which is created earleir with d6 insertion and d1 removal.