Description
Solutions
Photo Album

There is a collection of photos to place into an empty photo album, one at a time by order of importance. Each time a photo is inserted, all subsequent photos are shifted toward the right by one position. Given the id's of the photos and the positions where each should be placed, find out the sequence of the photos in the album after all photos have been inserted.

Function Description

Complete the function photoAlbum in the editor.

photoAlbum has the following parameter(s):

  1. int index[n]: the positions where the photos are to be inserted
  2. int identity[n]: the photograph id numbers

Returns

int[n]: the sequence of identity values after all are inserted

Input Format For Custom Testing

The first line contains an integer, n, the number of elements in the array index.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, index[i].
The next line contains an integer, n, the number of elements in the array identity.
Each line i of the n subsequent lines (where 0 ≤ i < n) contains an integer, identity[i].

Example 1:

Input:  index = [0, 1, 1], identity = [0, 1, 2]
Output: [0, 2, 1]
Explanation:
The output array goes through the following steps: [0] -> [0, 1] -> [0, 2, 1].

Example 2:

Input:  index = [0, 0], identity = [0, 1]
Output: [1, 0]
Explanation:
The output array goes through the following steps: [0] -> [1, 0].

Example 3:

Input:  index = [0, 1, 0], identity = [0, 1, 2]
Output: [2, 0, 1]
Explanation:
The output array goes through the following steps: [0] -> [1, 0] -> [2, 0, 1].
Constraints:
  • 1 ≤ n ≤ 2 x 105
  • 0 ≤ index[i], identity[i] < n (0 ≤ i < n)
Thumbnail 0
Testcase

Result
Case 1

input:

output: