Category: String coding problemYou are given a chronologically sorted list of stock transactions. Each transaction is a list of strings in the format `[<timestamp>, <type>,...Input: Array of strings Output: Computed result
codingHardVerified Question#2
2. Plane Cargo Allocator
Category: Algorithm coding problemA shipping terminal receives orders and must route cargo to available docks. Each dock has a fixed dispatch time and a remaining load capacity. An...Input: List Output: Computed result
codingHardVerified Question#3
3. [CodeSignal] Fibonacci Storage System
Category: Graph coding problemA research facility stores artifacts in underground vaults. Each vault has multiple tiers, indexed from 0 (deepest) upward. The capacity of each tier...Input: Graph (nodes and edges) Output: Computed result
codingHardVerified Question#4
4. [CodeSignal] Fixed Price Purchase Optimizer
Category: Algorithm coding problemA procurement team must purchase n identical components one at a time. For each component, the quoted market price is drawn independently and...Input: Given input Output: Integer
codingMediumVerified Question#5
5. [CodeSignal] Portfolio Path Counter
Category: Algorithm coding problemA warehouse manager starts with initial units of inventory. In one operation, the manager can either restock one unit (increase inventory by 1) or...Input: Number(s) Output: Integer
codingMediumstack queue#1
1. CODING — Implement a circular buffer queue
Background: In trading systems like those at Optiver, managing data streams effectively is crucial for performance. A circular buffer queue is an efficient way to handle a fixed-size buffer that can be filled and read from simultaneously. Problem statement: Implement a class CircularBufferQueue with methods to enqueue and dequeue elements in a circular manner. The enqueue method should add an element, and if the queue is full, it should overwrite the oldest element. The dequeue method should remove and return the front element. Function/class signature:
def __init__(self, capacity: int) -> None:
def enqueue(self, value: Any) -> None:
def dequeue(self) -> Any:
def is_empty(self) -> bool:
def is_full(self) -> bool:
Example 1: Input: cbq = CircularBufferQueue(3)cbq.enqueue(1)cbq.enqueue(2)cbq.enqueue(3)cbq.enqueue(4)out = cbq.dequeue() Output: 1 Explanation: After adding four elements, the first element (1) has been overwritten by the last enqueued element (4), thus when dequeuing it returns 1. Example 2: Input: cbq.enqueue(5)out = cbq.dequeue() Output: 2 Constraints:
Capacity of the buffer (1 <= capacity <= 1000)
Number of operations will not exceed 10^6
Values can be any type.
codingMediumstack queue#2
2. CODING — Implement a Circular Queue
Background: In the context of high-frequency trading systems at Optiver, efficient handling of orders and market data is crucial. A circular queue provides an efficient way to manage this data without wasting space. Problem statement: Design a CircularQueue class that implements a circular queue with basic operations such as enqueue, dequeue, and is_empty. The queue should be of fixed size, and once it reaches its maximum capacity, new items should overwrite the oldest items. Function/class signature:
def __init__(self, size: int) -> None:
def enqueue(self, item: Any) -> None:
def dequeue(self) -> Any:
def is_empty(self) -> bool:
Example 1: Input:
queue = CircularQueue(3)
queue.enqueue(1)
queue.enqueue(2)
queue.enqueue(3)
queue.enqueue(4) # This should overwrite 1
Output: queue.dequeue() returns 2 Example 2: Input:
Each enqueue/dequeue operation is expected to be O(1).
codingMediumstack queue#3
3. Queue Implementation using Circular Buffer — Implement a queue with fixed size using a circular buffer.
Background: Optiver's trading systems require efficient data structures to handle high volumes of market data in real-time. An effective way to manage incoming data events is through a circular buffer queue, which allows efficient use of memory and quick access.Problem statement: Implement a CircularQueue class that has a fixed size. It should allow for the operations of enqueue (adding an element to the queue), dequeue (removing an element from the front of the queue), and peek (looking at the front element without removing it). Ensure that these operations handle the wrap-around mechanism when the end of the buffer is reached. When the queue is empty, the dequeue and peek operations should return None.Function/class signature:
class CircularQueue:
def __init__(self, size: int): # initializes the queue with a given size
def enqueue(self, value: Any) -> bool: # adds value to the queue, returns success
def dequeue(self) -> Optional[Any]: # removes and returns the front value
def peek(self) -> Optional[Any]: # returns the front value without removing it
def is_empty(self) -> bool: # checks if the queue is empty
def is_full(self) -> bool: # checks if the queue is full
Example 1: Input: cq = CircularQueue(3); cq.enqueue(1); cq.enqueue(2); cq.enqueue(3); cq.dequeue(); cq.peek() Output: 2 Explanation: After dequeuing 1, the next element 2 is at front.Example 2: Input: cq = CircularQueue(2); cq.enqueue(1); cq.enqueue(2); cq.enqueue(3) Output: False Explanation: The third enqueue returns False because the queue is full.Constraints:
The maximum size of the queue is 1 <= size <= 1000.
The enqueue operation must handle the case when the queue is full gracefully.
Elements can be of any type, but focus on integer inputs initially for simplicity.
codingMediumqueue#4
4. [Queue Implementation] — Implement a circular buffer queue
Background: Optiver relies heavily on efficient data processing and messaging systems in high-frequency trading. Implementing a circular buffer helps in managing queues of order requests efficiently, minimizing resource usage and enhancing performance. Problem statement: Design and implement a CircularBufferQueue class that implements a circular queue with the following operations: enqueue to add an item to the queue, dequeue to remove an item, and is_empty to check if the queue is empty. The queue should have a fixed size limit to ensure efficient memory usage and prevent overflow. Use None or an alternative mechanism to represent an empty slot in the buffer. Function/class signature:
class CircularBufferQueue:
def __init__(self, size: int):
def enqueue(self, item: Any) -> bool:
def dequeue(self) -> Any:
def is_empty(self) -> bool:
Example 1:
Input:cbq = CircularBufferQueue(3)
Input:cbq.enqueue(1) → Output:True
Input:cbq.enqueue(2) → Output:True
Input:cbq.dequeue() → Output:1
Explanation: The circular buffer behaves as expected, the first element is dequeued after two elements are enqueued.
Example 2:
Input:cbq.enqueue(3) → Output:True
Input:cbq.enqueue(4) → Output:True
Input:cbq.dequeue() → Output:2
Explanation: The queue allows for overwriting the oldest item when it’s full, maintaining the circular nature of the buffer.
Constraints:
The size of the queue will be between 1 and 1000.
The items in the queue can be of any type.
Enqueue operations should be O(1) and must handle overflow gracefully.
Dequeue operations should be O(1).
system designMediumqueue#5
5. Design CircularBufferQueue — Implementation of a circular buffer queue
Background: In trading systems, efficient management of orders and trades is crucial for optimizing performance. A circular buffer queue can help manage orders in a first-in-first-out (FIFO) manner while utilizing fixed memory efficiently.Requirements: 1. Implement a circular buffer with a specified capacity. 2. Provide methods to enqueue and dequeue items from the queue. 3. Ensure that the queue supports checking if it is empty or full. 4. Methods must handle concurrent access safely. 5. Provide a method to clear the queue.Class API:
def __init__(self, capacity: int) -> None: Initializes the circular buffer queue with a given capacity.
def enqueue(self, item: Any) -> None: Adds an item to the queue. Raises an error if the queue is full.
def dequeue(self) -> Any: Removes and returns the item at the front of the queue. Raises an error if the queue is empty.
def is_empty(self) -> bool: Returns True if the queue is empty, otherwise False.
def is_full(self) -> bool: Returns True if the queue is full, otherwise False.
def clear(self) -> None: Clears all items from the queue.
Example 1: Input: CircularBufferQueue(3) followed by enqueue(1), enqueue(2), enqueue(3), dequeue() → Output: 1 → Explanation: The queue initially contains [1,2,3]. After dequeuing, the first item is removed.Example 2: Input: CircularBufferQueue(2) followed by enqueue(10), enqueue(20), enqueue(30) → Output: Error → Explanation: The third enqueue operation fails because the queue is full.Constraints:
capacity (1 <= capacity <= 10000)
Number of enqueue and dequeue operations should not exceed 10000.
Proper handling of concurrent accesses should be provided.
system designMediumcaching#6
6. Design CircularBuffer — Implementation of a circular buffer for efficient queue management
Background: At Optiver, software systems must efficiently handle real-time data processing and manage state changes. A circular buffer can provide efficient storage for incoming data streams, reducing overhead needed for dynamic resizing. Requirements: 1. The buffer must be able to store a fixed maximum number of elements. 2. It should provide methods to add an element to the buffer and retrieve the oldest element. 3. Implement methods to check if the buffer is empty or full. 4. Ensure thread safety when accessing the buffer. Class API:
def __init__(self, capacity: int) -> None: Initializes the circular buffer with a given capacity.
def enqueue(self, value: Any) -> None: Adds an element to the buffer, raises an exception if the buffer is full.
def dequeue(self) -> Any: Removes and returns the oldest element, raises an exception if the buffer is empty.
def is_full(self) -> bool: Returns True if the buffer is full, otherwise False.
def is_empty(self) -> bool: Returns True if the buffer is empty, otherwise False.
Example 1: Input: cb = CircularBuffer(3); cb.enqueue(1); cb.enqueue(2); cb.enqueue(3) → Output: None, Explanation: The buffer contains [1, 2, 3]. Example 2: Input: cb.dequeue() → Output: 1, Explanation: Removes 1, buffer now contains [2, 3]. Constraints:
Maximum capacity of the buffer: 1 <= capacity <= 10^6.
Buffer operations must handle concurrent access safely.
Start practicing Optiver questions
Sign up for free to access walkthroughs, AI-generated questions, and more.