Problem bank

Problem 240 of 333MediumCodingP240

Stock span

  1. Given a list of daily closing prices, the span on day ii is the number of consecutive days ending at day ii (including day ii itself) whose close is at most the close on day ii. For prices 100, 80, 60, 70, 60, 75, 85 the spans are 1, 1, 1, 2, 1, 4, 6. Compute every span in O(n)O(n) time.