Online Stock Span
Updated
Problem statement
You receive daily stock prices in chronological order. For each day, its span is the maximum number of consecutive days ending on that day whose prices are less than or equal to the current price.
Return the span for every price in prices. Treat the array as a series of calls to an online next method: process the prices from left to right and never look ahead.
Function
calculateStockSpans(prices: int[]) → int[]Examples
Example 1
prices = [100,80,60,70,60,75,85]return = [1,1,1,2,1,4,6]At price 75, the consecutive suffix [60,70,60,75] contributes span four; price 100 blocks the final price 85 at span six.
Constraints
1 <= prices.length <= 10000.1 <= prices[i] <= 100000.
More Tokopedia interview questions
- Validate Binary Search TreeONSITE INTERVIEW · Seen Aug 2021
- Kth Largest Element in an ArrayONSITE INTERVIEW · Seen Jul 2021
- Vertical Order Traversal of a Binary TreeONSITE INTERVIEW · Seen Jul 2021
- Interleaving StringPHONE SCREEN · Seen Jul 2021
- Delete Node in a BSTPHONE SCREEN · Seen Jul 2021
- Rotate ImagePHONE SCREEN · Seen Jul 2021
Similar questions at other companies
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Stack with Constant-Time Middle QueriesAmazon · PHONE SCREEN
- Adding Stack 2.0IMC Trading · OAIMC Trading interview questions
- Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
- Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
- KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
- Min StackDP World · ONSITE INTERVIEW
- Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
- Design Browser HistoryBloomberg LP · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Top K Largest Values from a StreamThe D.E. Shaw Group · ONSITE INTERVIEWThe D.E. Shaw Group interview questions