Array — Insert, Delete and Update

Practice this coding question on Coding Gurukul.

Problem statement

Implement an array that starts empty. Process these commands in order: - INSERT i x: insert x at index i and shift later elements right. Index i may equal the array length. - DELETE i: remove the element at index i and shift later elements left. - SET i x: change the element at index i to x. - GET i: print the element at index i. - SIZE: print the number of elements. All indices are zero-based and valid. Only GET and SIZE print output. Repeated and negative values are allowed. Worked example The array becomes [7], then [3, 7]. GET 1 prints 7. SET 1 9 changes it to [3, 9], and DELETE 0 leaves [9]. The remaining outputs are 1, 9 and 1.

Input format

First line: q. Next q lines: INSERT i x, DELETE i, SET i x, GET i, or SIZE.

Output format

Print each GET or SIZE result on its own line.

Constraints

1 <= q <= 2000; -10^9 <= x <= 10^9. At least one output command is present.

Sample input

8
INSERT 0 7
INSERT 0 3
GET 1
SET 1 9
DELETE 0
SIZE
GET 0
SIZE

Sample output

7
1
9
1

Sign in to run or submit a solution in C++, Java or Python.