Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

The stock span of day i is the number of consecutive days up to and including i with price at most price[i]. What is the sum of the spans for prices [100, 80, 60, 70, 60, 75, 85]?

  1. A. 15
  2. B. 19
  3. C. 28
  4. D. 16

Correct answer: D. 16

A monotonic stack gives each span as i minus the index of the previous strictly greater price. The spans are 1,1,1,2,1,4,6, which total 16.

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

Exams that ask this topic