Question: C++ ONLY You are given an array of n positive integers. The next line will contain an integer k. You need to tell whether there

C++ ONLY

You are given an array of n positive integers. The next line will contain an integer k. You need to tell whether there exists more than one occurrence of k in that array or not. If there exists more than one occurrence of k print YES, Otherwise print NO.

See the sample input-output for more clarification.

Note - The given array will be sorted in increasing order. And it is guaranteed that at least one occurrence of k will exist.

** Solve this problem using binary search means O(logn)**

Sample input 1- Sample output 1-

7

1 3 4 6 6 9 17 YES

6

Sample input 2- Sample output 2-

10

1 2 3 4 5 6 7 8 9 10 NO

5

Explanation -

In sample input 1 there exist two occurrences of k, hence the answer is YES

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!