Data Structures & AlgorithmsModerateLeetCode-style · TCS NQT

For daily temperatures [73, 74, 75, 71, 69, 72, 76, 73], the wait for day i 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. 13
  3. C. 4
  4. D. 6

Correct answer: A. 10

Monotonic stack of indices with decreasing temperatures: when a warmer day arrives, pop and assign each popped day the distance. Checking only the next day misses waits longer than one day.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic