Implement a fixed-capacity generic circular buffer
Company: Applied
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates knowledge of data structure design, generic types, in-place memory allocation, and constant-time FIFO operations required for implementing a fixed-capacity circular buffer.
Constraints
- Inputs are provided as Python literals compatible with the function signature.
- Return a deterministic value exactly matching the requested output.
Examples
Input: (3, [['push', 1], ['push', 2], ['push', 3], ['snapshot'], ['push', 4], ['snapshot'], ['pop'], ['peek']])
Expected Output: [[1, 2, 3], [2, 3, 4], 2, 3]
Explanation: Overwrite oldest.
Input: (2, [['pop'], ['push', 'a'], ['peek'], ['push', 'b'], ['push', 'c'], ['snapshot']])
Expected Output: [None, 'a', ['b', 'c']]
Explanation: Empty pop and strings.
Input: (0, [['push', 1], ['snapshot']])
Expected Output: []
Explanation: Zero capacity.
Hints
- Start with a direct data structure representation.
- Handle edge cases before the main loop.