O(nlogn) time and O(1) space complexity java solution


#1
public class Solution {
    public int solve(ArrayList<Integer> A) {
        Collections.sort(A);
        for (int i = 0; i < A.size() ; i++) { 
            if(A.get(i) == (A.size() - 1) - i) { // Value at this index is equal to the number of values at the right side from this index 
                // So there are list.get(i) in the right of array they can be same and different also
                // Check if next is same if yes return -1 else return 1
                if(i+1 < A.size() && A.get(i) == A.get(i+1)) {
                    return -1;
                }
                return 1;
            }
        }
        return -1;
    }
}