Problem-Solving with Leetcode | Shuffle String | Easy 1

Sagore Sarker
2 min readMar 6, 2022

Let’s talk about a LeetCode easy problem. Today we’ll discuss the Shuffle String (LeetCode number 1528).

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

Return the shuffled string.

Shuffle String | Leetcode 1528

From the above example, you may understand the problem. But how do we step through its solution? If you can’t understand the problem, I have a little explanation for you. As input, you have given a string, S, and its index value, indices, by the corresponding character. You have to place the character according to their corresponding index.

So, how do we solve it both in Python and Golang?

The main idea to solve the problem is, to insert the character with its corresponding index and build a string and return it. It is quite an easy task.

First, initialize a list with the length of the given string. Run a for loop to iterate over the list and insert the character to its corresponding index. Then join the list and return. Yeah, you have done it. For your help, here I share my python and Golang code.

Happy Coding :)

--

--

Sagore Sarker

I’m doing by Bachelor Degree in Computer Science and Engineering from a public university in Bangladesh. And interested in writing coding related article.