Data Structures & AlgorithmsModerateProduct Company SDE · Infosys OA
Problem: The list [25, 14, 9, 31, 7, 18, 3, 12] is turned into a min-heap in place with heapify (standard bottom-up sift-down, 0-indexed). What value is at index 1 afterwards?
- A. 9
- B. 25
- C. 7
- D. 14
Correct answer: C. 7
Bottom-up sift-down from index 3 to 0 gives [3, 7, 9, 12, 14, 18, 25, 31], so index 1 holds 7. Building the heap by pushing elements one at a time gives [3, 9, 7, …] (9), a max-heap puts 25 there, and 14 is just the original index-1 value.
More Coding Interview Problems questions
- Problem: The sorted array [2, 4, 4, 4, 7, 9, 9, 12] is searched with bisectleft and bisectright. What is bisectright(a, 4) − bisectleft(a…
- Problem: Compute (7^2026 + 11^2026) mod 1000, where ^ is exponentiation.
- Problem: Maximum number of non-overlapping meetings that can be held in one room, where a meeting is an interval [start, end) and two…
- Problem: How many contiguous subarrays of [3, -1, 4, -2, 5, -6, 2, 1] have sum at most 6 when the sum is computed over all non-empty…
- Problem: Longest substring without repeating characters of "pwwkewabcdbbxq". What is its length?
- Problem: Build a binary search tree by inserting 50, 30, 70, 20, 40, 60, 80, 35, 45, 65 in that order (duplicates are not inserted). Count…