Design body camera checkout system
Company: Axon
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
Quick Answer: This question evaluates competency in in-memory data structure design, algorithmic complexity (achieving O(1) average operations), and randomized resource allocation for exclusive assignments like device checkouts.
Constraints
- 0 <= len(camera_ids) <= 200000
- 0 <= len(operations) <= 200000
- `camera_ids` contains unique integers
- Each operation name is one of: `check_out`, `check_in`, `get_camera`
- Officer IDs and camera IDs fit in a signed 32-bit integer range
Examples
Input: ([10, 20, 30], [('check_out', 1), ('check_out', 2), ('get_camera', 1), ('check_in', 1), ('check_out', 3), ('get_camera', 1), ('get_camera', 3)], 1)
Expected Output: [30, 20, 30, 30, 10, None, 10]
Explanation: With seed 1, the first successful checkouts pick cameras 30 and 20. After officer 1 checks in camera 30, the next seeded checkout selects camera 10.
Input: ([], [('check_out', 1), ('get_camera', 1), ('check_in', 1)], 5)
Expected Output: [None, None, None]
Explanation: Edge case: there are no cameras at all, so every operation returns None.
Input: ([1], [('check_out', 7), ('check_out', 7), ('check_out', 8), ('get_camera', 7), ('check_in', 7), ('check_out', 8), ('get_camera', 8)], 0)
Expected Output: [1, 1, None, 1, 1, 1, 1]
Explanation: Officer 7 keeps the same camera on a repeated checkout. Officer 8 cannot get one until officer 7 checks camera 1 back in.
Input: ([5, 6, 7, 8], [('check_out', 1), ('check_out', 2), ('check_out', 3), ('check_in', 2), ('check_out', 4), ('get_camera', 3), ('check_in', 5), ('check_in', 1), ('check_out', 5), ('get_camera', 4)], 2)
Expected Output: [6, 8, 7, 8, 5, 7, None, 6, 8, 5]
Explanation: This case exercises multiple successful checkouts, a failed check-in for an officer with no camera, and the changing available array after swap-pop removals and append-on-check-in.
Hints
- Use a hash map from `officer_id` to the camera currently assigned to that officer.
- Store available cameras in a dynamic array. To remove a chosen camera in O(1), swap it with the last element and pop.