Find First Element Greater Than K
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.
Example 1
5 3 1 2 3 4 5
3
The first element greater than 3 is 4 at index 3.
Example 2
4 10 2 4 6 8
-1
There is no element strictly greater than 10 in the array, so -1 is printed.
Hints
# Read the input from stdin and print the answer.
import sys
def main():
data = sys.stdin.read().split()
# your code here
main()
5 3 1 2 3 4 5
4 10 2 4 6 8