Checkpointed Dynamic Sequence
Problem statement
Maintain a dynamic sequence of strings. The sequence starts empty and is represented by a linked list plus checkpoint references spaced every checkpointInterval positions.
Process operations in order. Each operation has one of these forms:
["ADD", index, value]: insertvalueimmediately before the current element at the zero-basedindex. Whenindexequals the current size, append the value. This operation produces no output.["GET", index]: return the value at the zero-basedindex.
The index and interval fields are decimal strings. All operations are valid when they are processed. Return the GET results in operation order.
Examples
Example 1
checkpointInterval = 3operations = [["ADD","0","A"],["ADD","1","C"],["ADD","1","B"],["GET","0"],["GET","1"],["GET","2"]]return = ["A","B","C"]The middle insertion places B before C. The three reads then return the sequence in index order.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 2 more worked examples, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.