Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Oracle8I Building Efficient Databases

Authors: Jonathan Lewis

1st Edition

0201715848, 978-0201715842

More Books

Students also viewed these Databases questions

Question

Which team solution is more likely to be pursued and why?

Answered: 1 week ago

Question

Did the team members feel that their work mattered

Answered: 1 week ago