Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: Daily temperatures are [73, 74, 75, 71, 69, 72, 76, 73]. For each day, the wait is the number of days until a strictly warmer day (0 if none). What is the sum of all waits?
- A. 10
- B. 25
- C. 6
- D. 21
Correct answer: A. 10
Waits are 1, 1, 4, 2, 1, 1, 0, 0, summing to 10. Storing the warmer day's index instead of the gap gives 25, counting days that have a warmer day gives 6, and measuring to the hottest day (76) gives 21.
More Coding Interview Problems questions
- Problem: In the binary array [1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1] at most 2 zeros may be flipped to 1. What is the length of the longest run…
- Problem: Starting from the empty set, a process inserts the numbers 5, 3, 8, 1, 4, 7 into a binary search tree, and then deletes nothing…
- Problem: The array [4, 2, 5, 1, 3] is turned into a max-heap by sift-down from the last parent to the root (standard heapify, 0-indexed)…
- Problem: A string is "racecar" and we ask: how many substrings of length 2 or 3 are palindromes (counted by index ranges)?
- Problem: The array [6, 1, 9, 4, 4, 8] is scanned, and for each index the number of earlier elements that are strictly smaller is recorded…
- Problem: The array [1, 5, 2, 6, 3, 7, 4, 8] is split into two halves, [1, 5, 2, 6] and [3, 7, 4, 8]. The result is formed by interleaving…