You are given a sorted array arr[] of distinct integers in non-decreasing order and an integer k, return true if k is present in the array, otherwise false.
Note: If multiple occurrences are there, please return the smallest index.
Example 1
Input: arr[] = [1, 2, 3, 4, 5], k = 4
Output: 3
Explanation: 4 appears at index 3.
Example 2
Input: arr[] = [11, 22, 33, 44, 55], k = 445
Output: -1
Explanation: 445 is not present.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
5 11 22 33 44 55 445
-1
5 1 1 1 1 2 1
0
5 1 2 3 4 5 4
3