PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches

Quick Overview

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.

  • medium
  • Axon
  • Coding & Algorithms
  • Software Engineer

Design body camera checkout system

Company: Axon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

You are building an in-memory checkout system for police body cameras. The system is initialized with a set of unique camera IDs. Each officer can hold at most one camera at a time, and each camera can be assigned to at most one officer. Implement the following operations: - `check_out(officer_id)`: randomly select one currently available camera, assign it to the officer, and return the camera ID. If no camera is available, return `null`. - `check_in(officer_id)`: return the camera currently assigned to that officer to the available pool. If the officer has no camera, do nothing or return an error. - `get_camera(officer_id)`: return the camera currently assigned to the officer, or `null` if none. All operations should run in `O(1)` average time. Explain the data structures you would use and how you support random assignment in constant time.

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.

Design an in-memory checkout system for police body cameras. You are given: - `camera_ids`: a list of unique integer camera IDs. This list is also the initial order of the available-camera array. - `operations`: a list of operations of the form `('check_out', officer_id)`, `('check_in', officer_id)`, or `('get_camera', officer_id)`. - `seed`: an integer used for reproducible pseudo-random assignment. Rules: - Each officer can hold at most one camera at a time. - Each camera can be assigned to at most one officer at a time. - `check_out(officer_id)`: if the officer already has a camera, return that camera and do not change the system. If no camera is available, return `None`. Otherwise, pick one available camera using the deterministic rule below, assign it to the officer, and return the camera ID. - `check_in(officer_id)`: if the officer currently has a camera, return it to the available pool and return that camera ID. If not, return `None`. - `get_camera(officer_id)`: return the officer's current camera, or `None`. Deterministic assignment rule for a successful new checkout: 1. Maintain an integer `state`, initially equal to `seed`. 2. Update `state = (state * 31 + 7) % 1000003`. 3. Let `m` be the number of available cameras. Choose index `state % m` from the current available-camera array. 4. Remove that camera by swapping it with the last camera in the available array and popping the last element. 5. When a camera is checked in, append it to the end of the available-camera array. Return a list containing the result of every operation in order. Your implementation should make each operation run in O(1) average time.

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

  1. Use a hash map from `officer_id` to the camera currently assigned to that officer.
  2. Store available cameras in a dynamic array. To remove a chosen camera in O(1), swap it with the last element and pop.
Last updated: Apr 19, 2026

Related Coding Questions

  • Find accessible devices via nested memberships - Axon (medium)
  • Implement encryption and constant-time random set - Axon (medium)

Loading coding console...

PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.