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.
I'm seeing a lot of dictionaries in the comments, but because the constraints declare the numbers are within 1 - 100, we can use a fast counting array, here's my C# solution.
const int lim = 100;
int[] count = new int[lim];
for(int i = 0; i < a.Count; ++i) ++count[a[i]];
int max = 0;
for(int i =1; i < lim; ++ i)
{
max = Math.Max(count[i]+count[i-1],max);
}
return max;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Picking Numbers
You are viewing a single comment's thread. Return to all comments →
I'm seeing a lot of dictionaries in the comments, but because the constraints declare the numbers are within 1 - 100, we can use a fast counting array, here's my C# solution.