Find First Element Greater Than KEasy

Find First Element Greater Than K

EasyPractice library · +10 XPtwo pointersbinary searchsorted array

You are given a sorted array of integers A and an integer K. Your task is to find the index of the first element in the array A that is strictly greater than K. If no such element exists, return -1.

The array A is guaranteed to be sorted in non-decreasing order.

Input

The first line contains two integers N and K, where N is the number of elements in the array. The second line contains N space-separated integers representing the array A.

Output

Print a single integer representing the 0-based index of the first element in A that is strictly greater than K. If no such element exists, print -1.

Constraints

1 <= N <= 1000 -10^9 <= A[i] <= 10^9 for all i -10^9 <= K <= 10^9 A is sorted in non-decreasing order.

Time limit 1 s (native code; slower languages get more)Memory 256 MB15 hidden tests

Example 1

Input
5 3
1 2 3 4 5
Output
3

The first element greater than 3 is 4 at index 3.

Example 2

Input
4 10
2 4 6 8
Output
-1

There is no element strictly greater than 10 in the array, so -1 is printed.

Hints