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.
Picking Numbers
Picking Numbers
Sort by
recency
|
2488 Discussions
|
Please Login in order to post a comment
Regarding some test case after the submission, the official answer is 3 but I found the longest subarray shall be [24,25,26,27] or [56,55,55,54] or [99,98,97,96] with 4 numbers. The official answer apparently wrong. What is going on?
public static int pickingNumbers(List a) { Dictionary frequency = new Dictionary(); int longestNumber = 0; foreach(int number in a) { if (frequency.ContainsKey(number)) frequency[number]++; else frequency[number] = 1; }
Hi there! Here's my Java solution for the challenge.
https://github.com/eduardocintra/hacker-rank-solutions/blob/master/src/br/com/eduardocintra/easy/pickingnumbers/PickingNumbers.java
Javascript Solution: Loop within the a array with each number using filter to get the numbers that >= 0 or <=1 then get the longest array length
JavaScript