201. Shuffle String

EasyStringString

You are given a string s and an integer array indices of the same length.

The string s will be shuffled such that the character at the i-th position moves to indices[i].

Return the shuffled string.

Input format: s|i0|i1|...|in-1

Input: String s followed by '|' and then each index separated by '|'.

Output: The shuffled string.

Examples

Example 1
Input: codeleet|4|5|6|7|0|2|1|3
Output: leetcode
Explanation: c→4,o→5,d→6,e→7,l→0,e→2,e→1,t→3 → 'leetcode'.
Example 2
Input: abc|0|1|2
Output: abc
Explanation: Identity permutation — no change.
Example 3
Input: abc|2|1|0
Output: cba
Explanation: a→2,b→1,c→0 → 'cba'.

Constraints

Asked by

MicrosoftGoogle
Solve this problem in the editor →