Implement classes in existing abstract hierarchy
Company: Bloomberg
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates object-oriented design and implementation skills in Python within the Coding & Algorithms and software engineering domain, focusing on completing concrete subclasses in an existing abstract class hierarchy while preserving public interfaces and type compatibility.
Constraints
- 0 <= len(commands) <= 200000
- 1 <= len(key), len(prefix) <= 30
- -10^9 <= value, delta <= 10^9
- All prefix sums fit in a signed 64-bit integer
- Only successful SET, ADD, and DELETE commands are undoable; GET, SUM, invalid commands, and ROLLBACK itself are not recorded as mutations
Examples
Input: (['SET apple 3', 'SET app 2', 'SUM app', 'ADD apple 4', 'GET apple', 'SUM ap'],)
Expected Output: ['5', '7', '9']
Explanation: Both app and apple match prefix app for a sum of 5. After adding 4 to apple, apple is 7 and the sum for prefix ap is 9.
Input: (['GET missing', 'DELETE missing', 'SET x 10', 'DELETE x', 'GET x', 'ROLLBACK 1', 'GET x', 'ROLLBACK 2', 'GET x'],)
Expected Output: ['NULL', 'ERROR', 'NULL', '10', 'ERROR', '10']
Explanation: Deleting a missing key is an error. Rolling back one successful mutation restores x. Rolling back two more mutations fails because only one undoable mutation remains.
Hints
- Use concrete command objects with common validate and execute methods so the processor can treat them polymorphically.
- For efficient SUM prefix queries under updates and rollback, maintain a running total for every prefix of each key whenever that key changes.