> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/strings-arrays-and-2-pointers/noble-integer.md).

# Noble Integer

Given an integer array **A**, find if an integer **p** exists in the array such that the number of integers greater than **p** in the array equals to **p**.\
\
**Input Format**<br>

First and only argument is an integer array A.\
\
**Output Format**<br>

Return 1 if any such integer p is found else return -1.\
\
**Example Input**<br>

Input 1:

```
 A = [3, 2, 1, 3]
```

Input 2:

```
 A = [1, 1, 3, 3]
```

\
\
**Example Output**<br>

Output 1:

```
 1
```

Output 2:

```
 -1
```

\
\
**Example Explanation**<br>

Explanation 1:

```
 For integer 2, there are 2 greater elements in the array. So, return 1.
```

Explanation 2:

```
 There is no such integer exists.
```

```java
class Solution {
    public int solve(int[] A) {
        Arrays.sort(A);
        for (int i = 0; i < A.length - 1; i++)
            if (A[i] == (A.length - (i + 1)) && A[i] != A[i + 1])
                return 1;
        if (A[A.length - 1] == 0)
            return 1;
        return -1;
    }
}
```
