Data Structures & AlgorithmsHardGoldman Sachs OA · LeetCode medium-hard
Array [90, 6, 26, 27, 39, 47, 79] 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 27 found?
- A. 4
- B. 2
- C. 3
- D. 6
Correct answer: C. 3
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 27 at index 3.
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
- Two sorted linked lists [12 → 17 → 24 → 26 → 32] and [8 → 10 → 12 → 38] are merged with the standard O(n+m) two-pointer merge (always take…
- The Dutch National Flag algorithm (single pass, three pointers low/mid/high) partitions [1, 1, 2, 2, 1, 1, 1, 1, 2, 0] (values 0, 1, 2…
- Heights [8, 6, 3, 2, 6, 8, 8, 4, 7, 1] represent vertical lines at each index. What is the maximum water area (min(height) × horizontal…
- Kadane's algorithm runs on the array [5, 4, 4, -3, -5, -1, 8] to find the maximum sum of a contiguous subarray. What sum does it return?
- What is the sum of the minimum element over every contiguous subarray of [9, 4, 5, 3, 1, 9, 8, 1]?
- QuickSort (last element as pivot, Lomuto-style partition) sorts [31, 34, 38, 59, 23, 16, 54, 42, 46]. Counting one comparison per element…