Noble Integer - The Coding Shala
Home >> Interview Questions >>  Noble Integer
Noble Integer InterviewBit Solution
Problem : 
Given an integer array, find if an integer 
p exists in the array such that the number of integers greater than p in the array equals to p. If such an integer is found return 1 else return -1.
Solution 1 (Java) :
  
public class Solution { public int solve(ArrayList<Integer> A) { Collections.sort(A); if(A.get(A.size()-1)==0) return 1; for(int i=0;i<A.size();i++){ if(A.get(i)==(A.size()-i-1) && A.get(i)!=A.get(i+1)) return 1; } return -1; } }
Other Posts You May Like

Comments
Post a Comment