Google | Reorder array according to the given indexes

Anonymous User
12292
Jun 11, 2019
Dec 20, 2020

Software Engineer Bay Area March 2019

Given two integer arrays of same size, nums and indexes, reorder elements in nums according to given indexes array.

Example 1:

Input: nums = [24, 56, 74, -23, 87, 91], indexes = [1, 2, 3, 0, 4, 5]
Output: [56, 74, -23, 24, 87, 91]

Example 2:

Input: nums = [10, 11, 12], indexes = [1, 0, 2]
Output: [11, 10, 12]

Expected O(n) time and O(1) space solution.

Comments (55)