Two-Type Ring Buffer
Updated
Problem statement
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 vandpushB b: append the typed value when space remains and returnTRUE. If the buffer is full, returnFALSEand leave it unchanged.pop: remove and return the oldest value, or returnEMPTYif empty.peek: return the oldest value without removing it, orEMPTYif empty.empty: returnTRUEexactly when the buffer is empty, otherwiseFALSE.full: returnTRUEexactly when the buffer is full, otherwiseFALSE.
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^51 <= operations.length <= 2 * 10^5- A values are between
-2^31and2^31 - 1, inclusive. - B values use exactly
trueorfalse. - 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