Data Structures & AlgorithmsVery hardProduct company OA
Array [83, 87, 90, 43, 45, 48, 62, 75, 82] is a sorted array rotated at pivot 6. Using the standard O(log n) rotated-array binary search (decide which half is sorted, then check if the target lies in it), at what index is 75 found?
- A. 6
- B. 8
- C. 2
- D. 7
Correct answer: D. 7
At each step one half (low..mid or mid..high) is guaranteed sorted; checking whether the target falls in that sorted half's range decides which half to keep. Tracing this on the array places 75 at index 7.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- Using a sliding window of fixed size with a character-frequency count, how many substrings of "AAABAAABCB" are anagrams of "BA"?
- Heights [6, 3, 1, 5, 9, 8, 9, 6, 4] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…
- Kadane's algorithm runs on the array [-9, 1, 7, 5, 7, -3, 0, -7, 1] to find the maximum sum of a contiguous subarray. What sum does it…
- QuickSort (last element as pivot, Lomuto-style partition) sorts [57, 6, 37, 10, 15, 58]. Counting one comparison per element checked…
- Using a sliding window (shrink from the left whenever more than k distinct characters are in the window), what is the length of the…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [2, 0, 0, 1, 0, 1, 1, 0] (values 0, 1, 2 only) in…