FastPrepStock Span I
Problems/Stock Span I

Stock Span I

Freshworks logoFreshworks● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report gives only the name Stock Span I. This version uses the usual definition on a whole batch of prices. Our version is about 80% the same as the reported question.

Given an array prices of daily stock prices, return one span for every day in the same order.

The span for day i is the number of consecutive days ending at i for which each price is less than or equal to prices[i]. The current day is always included.

Function

stockSpan(prices: int[]) → int[]

Examples

Example 1

prices = [100,80,60,70,60,75,85]return = [1,1,1,2,1,4,6]

For price 75, the consecutive suffix [60, 70, 60, 75] has four prices less than or equal to 75, so its span is 4.

Example 2

prices = [10,10,10]return = [1,2,3]

Equal previous prices extend the span because the comparison is less than or equal.

Constraints

  • 1 <= prices.length <= 200000
  • 1 <= prices[i] <= 2^31 - 1

More Freshworks interview questions

  • LFU CachePHONE SCREEN · Seen Sep 2026
  • Product Of Array Except SelfPHONE SCREEN · Seen Sep 2026
  • Flatten a Nested ArrayONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Asteroid CollisionSiemens · PHONE SCREEN
  • Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Daily TemperaturesCARS24 · PHONE SCREEN
  • Next Greater Indices and Maximum GapTikTok · PHONE SCREENTikTok interview questions
  • Next Greater Value in a Circular ArrayPayPay · PHONE SCREENPayPay interview questions
  • Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
  • Recover the Stack After a WorkerCitadel · PHONE SCREENCitadel interview questions
  • Generic Stack Operation SequenceArista Networks · PHONE SCREENArista Networks interview questions
  • Exclusive Function Execution TimeDecagon · PHONE SCREENDecagon interview questions
All Freshworks interview questionsSee Freshworks hiring insights
Saved
class Solution {
    public int[] stockSpan(int[] prices) {
      // write your code here
    }
}
Checking account…