FastPrepTwo-Type Ring Buffer
Problems/Two-Type Ring Buffer

Two-Type Ring Buffer

IMC Trading logoIMC Trading● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. Our task is about 70% the same as the reported ring buffer. The report asks for a C++ template with a fixed capacity and two POD types, but its public interface is cut off. This exercise takes a batch of commands, with the capacity fixed for the batch. It uses integer and boolean values, named methods, rules for full and empty buffers, and limits.

Implement a fixed-capacity FIFO ring buffer that holds values of two types: A is a signed 32-bit integer and B is a boolean. The capacity stays constant throughout the operation batch.

Process operations in order and return one result string for each operation:

  • pushA v and pushB b: append the typed value when space remains and return TRUE. If the buffer is full, return FALSE and leave it unchanged.
  • pop: remove and return the oldest value, or return EMPTY if empty.
  • peek: return the oldest value without removing it, or EMPTY if empty.
  • empty: return TRUE exactly when the buffer is empty, otherwise FALSE.
  • full: return TRUE exactly when the buffer is full, otherwise FALSE.

Serialize returned values as A:v or B:true/B:false. Preserve insertion order and each value's type. Implement the final ring-buffer approach with constant work per operation.

Function

ringBuffer(capacity: int, operations: String[]) → String[]

Examples

Example 1

capacity = 2operations = ["pushA 7","pushB true","full","pushA 9","peek","pop","pushA -2","pop","pop","empty"]return = ["TRUE","TRUE","TRUE","FALSE","A:7","A:7","TRUE","B:true","A:-2","TRUE"]

The queue preserves insertion order and each value's type. A rejected push leaves the queue unchanged.

Example 2

capacity = 1operations = ["pop","peek","pushB false","pushA 3","pop","full"]return = ["EMPTY","EMPTY","TRUE","FALSE","B:false","FALSE"]

The queue preserves insertion order and each value's type. A rejected push leaves the queue unchanged.

Constraints

  • 1 <= capacity <= 10^5
  • 1 <= operations.length <= 2 * 10^5
  • A values are between -2^31 and 2^31 - 1, inclusive.
  • B values use exactly true or false.
  • Commands are valid, with one space between a push command and its canonical payload.
  • Operations run sequentially in one thread.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Per-Client Sliding-Window Rate LimiterGeneral Motors · OA
  • Token Expiry with Lazy DeletionCitadel · OACitadel interview questions
  • Per-Domain Request LimiterExpedia · OAExpedia interview questions
  • Customer Checkout DurationOptiver · OAOptiver interview questions
  • Design Hit CounterAtlassian · OAAtlassian interview questions
  • Priority Message BufferAmazon · ONSITE INTERVIEW
  • Rate Limiter with a Sliding Window per ClientStackAdapt · PHONE SCREENStackAdapt interview questions
  • Rolling Hit CounterDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
  • Per-Client API Rate LimiterDocker · PHONE SCREEN

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public String[] ringBuffer(int capacity, String[] operations) {
        // Write your solution here.
    }
}
Checking account…