Data Structures & AlgorithmsHardGATE CS

The span of a day is the number of consecutive days ending that day (including it) whose price is at most that day's price. For prices [100, 80, 60, 70, 60, 75, 85, 90, 50, 95], what is the total of all the spans?

  1. A. 36
  2. B. 31
  3. C. 40
  4. D. 33

Correct answer: D. 33

The spans are [1, 1, 1, 2, 1, 4, 6, 7, 1, 9], which add to 33. Using a strict inequality (< instead of <=) changes the spans for repeated prices such as the two 60s.

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

Exams that ask this topic