Maximum Frequency Stack
Updated
Problem statement
Process operations on a frequency stack.
pushadds its value.popremoves and returns a value with the greatest current frequency. Among tied values, remove the one pushed most recently.
The value paired with a pop is ignored. Return the popped values in operation order.
Function
processFrequencyStack(operations: String[], values: int[]) → int[]Examples
Example 1
operations = ["push","push","push","push","push","push","pop","pop","pop","pop"]values = [5,7,5,7,4,5,0,0,0,0]return = [5,7,5,4]The first pop chooses frequency 3; later ties use push recency.
Example 2
operations = ["push","push","pop","pop"]values = [1,2,0,0]return = [2,1]Both values initially have frequency one, so 2 leaves first.
Example 3
operations = ["push","push","push","pop"]values = [9,9,3,0]return = [9]Frequency two beats the more recent frequency-one value.
Constraints
1 <= operations.length == values.length <= 20000.- Each operation is
pushorpop. 0 <= values[i] <= 10^9for pushes.- Every pop occurs while the structure is nonempty.
Similar questions at other companies
- Maximum Frequency StackAmazon · PHONE SCREEN
- Nested Recipe Cart TransactionsDecagon · PHONE SCREENDecagon interview questions
- Maximum Frequency StackInMobi · PHONE SCREENInMobi interview questions
- KV Store with Nested TransactionsApplied Intuition · PHONE SCREEN · ONSITE INTERVIEWApplied Intuition interview questions
- Layer History with Batch Undo and RedoFigma · OA · PHONE SCREENFigma interview questions
- In-Memory Database with Transactions and SavepointsNextdoor · PHONE SCREENNextdoor interview questions
- Key-Value Store with Nested TransactionsRippling · PHONE SCREEN · ONSITE INTERVIEWRippling interview questions
- Maximum Frequency StackBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Nested In-Memory Database TransactionsDRW · OADRW interview questions
- Nested Transaction Key-Value StorexAI · ONSITE INTERVIEWxAI interview questions