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?

  1. A. 10
  2. B. 25
  3. C. 6
  4. 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

Exams that ask this topic