Dsa
Stack
Easy
Calculate Stock Span
A stock span is defined as the number of consecutive days (up to the current day) for which the stock price was less than or equal to the price on the current day. You are given an array of stock prices, and you need to calculate the span for each day.
Input:
[100, 80, 60, 70, 60, 75, 85]
Output:
[1, 1, 1, 2, 1, 4, 6]
Input:
[30, 40, 50, 60, 50, 40, 30]
Output:
[1, 2, 3, 4, 1, 1, 1]
Key concepts
stackarrayfinancial-analysis
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now