Created
October 19, 2021 19:04
-
-
Save les-peters/12f2ca633bcf87f5baa24be606b2d235 to your computer and use it in GitHub Desktop.
Reorder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| question = """ | |
| Given an array of objects A, and an array of indexes B, reorder the objects in array A with the given indexes in array B. | |
| Example: | |
| let a = [C, D, E, F, G, H]; | |
| let b = [3, 0, 4, 1, 2, 5]; | |
| $ reorder(a, b) // a is now [D, F, G, C, E, H] | |
| """ | |
| def reorder(a,b): | |
| e = [''] * len(a) | |
| for i in range(0,len(a)): | |
| e[b[i]] = a[i] | |
| return e | |
| a = ['C', 'D', 'E', 'F', 'G', 'H'] | |
| b = [3, 0, 4, 1, 2, 5] | |
| print(reorder(a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment