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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started