Question bank › Stack
Dsa Stack Hard

Stock Span Problem

You are dealing with stock price data for a company. Your task is to calculate the span of stock prices, which is defined as the maximum number of consecutive days (up to the current day) that the price of the stock has been less than or equal to the current day's price. Implement a function that reads a list of stock prices and outputs the list of spans. Input Format: - A space-separated string of integers representing stock prices. Output Format: - A space-separated string of spans. Example: Input: 100 80 60 70 60 75 85 Output: 1 1 1 2 1 4 6

Key concepts

stackfinancearray

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.