Back to the 100
Problem 040Design
Medium

Insert Delete GetRandom O(1)

040

Simulate insert, remove, and getRandom with deterministic random indices. Return 1/0 for insert/remove and selected values for getRandom.

EXAMPLES

Example 1
Input
{
  "operations": [
    "insert",
    "remove",
    "insert",
    "getRandom"
  ],
  "values": [
    1,
    2,
    2,
    0
  ],
  "randomIndices": [
    0
  ]
}

Output
[
  1,
  0,
  1,
  1
]

FUNCTION SHAPE

operations: stringArrayvalues: intArrayrandomIndices: intArrayintArray
00:00
1 local tests readyRun with ⌘/Ctrl + Enter. Your code stays in this browser.

Runs solve(...) locally in a browser worker. SWE Playbook does not submit your code. Only run code you trust; Python code may access the network.