Shuffle String

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] in the shuffled string.

Return the shuffled string.

Example 1
Inputs = "codeleet", indices = [4,5,6,7,0,2,1,3]
Output"leetcode"
As shown, "codeleet" becomes "leetcode" after shuffling.
Example 2
Inputs = "abc", indices = [0,1,2]
Output"abc"
After shuffling, each character remains in its position.

Constraints

  • s.length == indices.length == n
  • 1 <= n <= 100
  • s consists of only lowercase English letters.
  • 0 <= indices[i] < n
  • All values of indices are unique.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate