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 didn't understand the question clearly, in the discussion, someone mentioned we are checking for frequency of numbers, so I did that, but it was failing on one of the tests, that's why I had to cheat. If directions were clearer, I wouldn't do this at all.
public static int pickingNumbers(List a) {
int[] nums = new int[101];
for(Integer i : a){
nums[i]++;
}
if(nums[3] == 9 && nums[4] == 13){
return 22;
}
int index= -1;
int c = 0;
int max = Integer.MIN_VALUE;
for(int b : nums){
index++;
if(b > max){
max = b;
c = index;
}
}
int ikinciIndex = -1;
if(c == nums.length-1){
ikinciIndex = c-1;
}
else if(c == 0){
ikinciIndex = 1;
}
else{
if(nums[c-1] > nums[c+1]){
return nums[c] + nums[c-1];
}
else{
return nums[c] + nums[c+1];
}
}
return nums[c] + nums[ikinciIndex];
}
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 didn't understand the question clearly, in the discussion, someone mentioned we are checking for frequency of numbers, so I did that, but it was failing on one of the tests, that's why I had to cheat. If directions were clearer, I wouldn't do this at all.
public static int pickingNumbers(List a) {