FastPrepImplement a Dynamic Array Vector

Implement a Dynamic Array Vector

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREEN
Learn

Problem statement

Implement a vector with a manually managed backing array. Process parallel operations and arguments:

  • append [value]: add a value.
  • get [index]: return the value.
  • set [index,value]: replace a value.
  • pop []: remove and return the last value.
  • size []: return the current size.

Return one string per command, using "null" for append and set. Grow the backing capacity geometrically; do not use a built-in resizable collection for stored elements.

Function

runDynamicVector(operations: String[], arguments: int[][]) → String[]

Examples

Example 1

operations = ["append","append","get","set","pop","size"]arguments = [[4],[7],[0],[0,9],[],[]]return = ["null","null","4","null","7","1"]

The set changes the remaining first value to 9 after pop removes 7.

Constraints

  • At most 10^5 commands.
  • Indices and pop operations are valid.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public String[] runDynamicVector(String[] operations, int[][] arguments) {
  // Write your code here.
}
operations["append","append","get","set","pop","size"]
arguments[[4],[7],[0],[0,9],[],[]]
expected["null", "null", "4", "null", "7", "1"]
Checking account…