Finding Number
Easy Accuracy: 8.78% Submissions: 1813 Points: 2

An array is called Bitonic if it is comprises of an increasing sequence of integers followed immediately by a decreasing sequence of integers.
Given a bitonic array Arr of N distinct integers. Find a element K in it.

Example 1:

Input: 
N = 9
Arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}
K = 3
Output: 8
Explanation: Found at index 8

Example 2:

Input: 
N = 9
Arr[] = {5, 6, 7, 8, 9, 10, 1, 2, 3}
K = 30
Output: -1
Explanation: 30 is not found in the array.

Your Task:  
You don't need to read input or print anything. Your task is to complete the function findNumber() which takes the array arr[], n and k as inputs and returns an array of integers denoting the answer. Return -1 if k is not found in the array.

Expected Time Complexity: O(logN)
Expected Auxiliary Space: O(1)

Constraints:
1 <= N <= 107
-107 <= Arri <= 107
-107 <= K <= 107

 

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.

Output Window