FastPrepMaximum Frequency Stack
Problems/Maximum Frequency Stack

Maximum Frequency Stack

Kalshi logoKalshi● HardFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Kalshi phone screen. Two firsthand phone-screen reports each name the well-known Maximum Frequency Stack problem. The newer one says the hour-long coding interview required implementing it and testing the solution. The array of operations is our way of running that named exercise. Our version is about 98% the same as the part of the reports we could recover.

Process operations on a frequency stack.

  • push adds its value.
  • pop removes 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 push or pop.
  • 0 <= values[i] <= 10^9 for 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
See Kalshi hiring insights
Saved
class Solution {
    public int[] processFrequencyStack(String[] operations, int[] values) {
        // Return values removed by pop operations.
    }
}
Checking account…