FastPrepFixed-Capacity Circular Buffer
Problems/Fixed-Capacity Circular Buffer

Fixed-Capacity Circular Buffer

Citadel logoCitadel● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Citadel Securities quantitative developer interview loop, in the coding rounds that came after the HR and manager interviews, posted in June 2026. The task was to build a circular buffer.

The report gives only that one line. It does not list the methods, the limits or what happens on a write when the buffer is full. Here, a full buffer rejects the write, and you also answer oldest, newest, empty and full checks. Reading from an empty buffer gives -1. You get the calls as a list of operations instead of a class. The limits and the examples are ours.

Our version is about 70% the same as the reported question.

Implement a circular buffer that holds at most capacity integers. Store the values in one array of length capacity that you create once and never resize. Do not use a built-in queue or deque.

The buffer starts empty. Process operations in order. Each operation is a pair of integers and records exactly one value:

  • [0, value]: write value after the newest stored value. If the buffer is full, the write is rejected and nothing changes. Record 1 if the value was stored, or 0 if it was rejected.
  • [1, 0]: remove the oldest stored value. Record 1 if a value was removed, or 0 if the buffer was empty.
  • [2, 0]: record the oldest stored value, or -1 if the buffer is empty.
  • [3, 0]: record the newest stored value, or -1 if the buffer is empty.
  • [4, 0]: record 1 if the buffer is empty, otherwise 0.
  • [5, 0]: record 1 if the buffer is full, otherwise 0.

Return the recorded values in operation order.

Function

circularBuffer(capacity: int, operations: int[][]) → int[]

Examples

Example 1

capacity = 3operations = [[0,10],[0,20],[0,30],[0,40],[3,0],[5,0],[1,0],[0,40],[3,0],[2,0]]return = [1,1,1,0,30,1,1,1,40,20]

The first three writes fill the buffer, so the write of 40 is rejected and records 0. The newest value is 30 and the buffer is full. Removing the oldest value drops 10. Now 40 fits. The newest value is 40 and the oldest is 20.

Example 2

capacity = 1operations = [[4,0],[1,0],[2,0],[0,7],[4,0],[5,0],[0,8],[1,0],[3,0]]return = [1,0,-1,1,0,1,0,1,-1]

The buffer starts empty, so the removal records 0 and the oldest value is -1. After 7 is written, the buffer of capacity 1 is not empty and is full. The write of 8 is rejected. Removing 7 empties the buffer, so the newest value is -1.

Constraints

  • 1 <= capacity <= 5000
  • 1 <= operations.length <= 5000
  • operations[i].length == 2
  • 0 <= value <= 10^6
  • The first integer of each operation is between 0 and 5. For operations 1 to 5, the second integer is 0.

More Citadel Onsite Interview questions

  • Maximize Workday EarningsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Minimum Changes for Palindromic BlocksOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Removal PoolONSITE INTERVIEW · Seen Sep 2026
  • Centered K-by-K Submatrix SumsONSITE INTERVIEW · Seen Aug 2026
  • Search Suggestions with a Prefix TreeONSITE INTERVIEW · Seen Aug 2026
  • Traverse Interior Matrix Cells in Row-Major OrderONSITE INTERVIEW · Seen Aug 2026
  • Limit Order Book Matching EnginePHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Stock Trading with a Fee and a CooldownONSITE INTERVIEW · Seen May 2026
  • Time-Based Key-Value StorePHONE SCREEN · ONSITE INTERVIEW · Seen Feb 2026
  • 2048 Simulation and Board CodecONSITE INTERVIEW · Seen Jan 2026

Similar questions at other companies

  • Round-Robin Iterator over IteratorsBridge · ONSITE INTERVIEWBridge interview questions
  • Design Hit CounterNutanix · ONSITE INTERVIEWNutanix interview questions
  • Five-Minute Hit CounterGoogle · ONSITE INTERVIEWGoogle interview questions
  • Ring Buffer OperationsAmazon · ONSITE INTERVIEW
  • Recent Hit CounterAmazon Web Services · ONSITE INTERVIEWAmazon Web Services interview questions
  • Design Hit CounterCharta Health · PHONE SCREENCharta Health interview questions
  • Constant-Time Weighted Pick with an Alias TableEtched · PHONE SCREEN
  • Implement a FIFO QueueByteDance · PHONE SCREENByteDance interview questions
  • Stateful Paginated Fetch NLyft · PHONE SCREENLyft interview questions
  • Music Player Operation SequenceAtlassian · PHONE SCREENAtlassian interview questions

Citadel interview experiences

  • Citadel Securities Quant Researcher Intern Loop: 1 Experience
  • Citadel Securities Research Engineer Interview: 1 Experience
  • Citadel Securities SWE Intern First Round: 2 Experiences
  • Citadel Securities Experienced SWE Interviews: 1 Experience
  • Citadel SWE Intern Later Rounds and Superday: 13 Experiences
  • Citadel SWE Intern First-Round Questions: 20 Experiences
All Citadel interview questionsSee Citadel hiring insights
Saved
class Solution {
    public int[] circularBuffer(int capacity, int[][] operations) {
      // Write your code here.
    }
}
Checking account…