Shuffle String - LeetCode

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 ith position moves to indices[i] in the shuffled string.

Return the shuffled string.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/54c1d3c5-eb08-485a-93b0-347d74a241b3/Screen_Shot_2021-04-01_at_11.51.20_AM.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d21c8370-ff22-463a-9184-7db43df81bfc/Untitled.png

"""
1528. Shuffle String

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 ith position moves to indices[i] in the shuffled string.

Return the shuffled string.

Input: s = "codeleet", indices = [4,5,6,7,0,2,1,3]
Output: "leetcode"
Explanation: As shown, "codeleet" becomes "leetcode" after shuffling.
"""

s = "aiohn"
indices = [3,1,4,2,0]

word = list(s)
i = 0

while i < len(indices):
    word[indices[i]] = s[i]
    
    i += 1

print(''.join(word))

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/cdd3666b-7906-482f-a6f7-a789927030ad/Screen_Shot_2021-04-01_at_11.52.18_AM.png