#C9139. First Occurrence in Sorted Array

    ID: 53199 Type: Default 1000ms 256MiB

First Occurrence in Sorted Array

First Occurrence in Sorted Array

You are given a sorted (in increasing order) array of integers and an integer (x). Your task is to find the index of the first occurrence of (x) in the array using binary search. If (x) is not present in the array, output -1. The binary search algorithm should run in (O(\log n)) time.

inputFormat

The first line contains two integers, (n) and (x), where (n) is the number of elements in the array and (x) is the target value. The second line contains (n) sorted integers separated by spaces. If (n = 0), the second line will be empty.

outputFormat

Output a single integer representing the index of the first occurrence of (x) in the array. If (x) is not found, output -1.## sample

7 4
1 2 4 4 5 6 8
2