Tricky Interview Question:

Revision en2, by saketkumarsingh, 2023-09-17 19:30:17

I was asked this question in the interview round of a company: Given an array of integers of size atleast 3, such that a[0]>=a[1].... And a[n-2]<=a[n-1] such that it gives a v shape (i.e. first it’s decreasing then its increasing) find the minimum element in the array.

The interviewer asked to implement in O(log n) , if all the elements would have been distinct then I coded the approach using binary search but could not come up with a log n solution in case of duplicates. Can someone help me out?

Tags binary search, interview

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English saketkumarsingh 2023-09-17 19:31:46 46
en2 English saketkumarsingh 2023-09-17 19:30:17 1 (published)
en1 English saketkumarsingh 2023-09-17 19:29:28 534 Initial revision (saved to drafts)