Data Structures & AlgorithmsModerateGATE CS · Codeforces Div2 B

Daily temperatures are 73, 74, 75, 71, 69, 72, 76, 73. For each day, the wait is the number of days until a warmer day (0 if none). What is the sum of all waits?

  1. A. 11
  2. B. {C+5}
  3. C. 10
  4. D. 13

Correct answer: C. 10

A decreasing monotonic stack resolves each cold day when a warmer one arrives. Waits are measured as index differences, not as the number of distinct days.

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

Exams that ask this topic