It's an easy problem by Leet Code, the description being:
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.
The image on the problem helps a lot to understand what needs to be done:
Indices array values give the index that the char from the string s supposed to be, iterating the indices and using that number to build a new String is the way to go.
class Solution {
public String restoreString(String s, int[] indices) {
char[] restoredString = new char[s.length()];
for(int i=0;i<s.length();i++){
restoredString[indices[i]] = s.charAt(i);
}
return new String(restoredString);
}
}
If there is anything thing else to discuss feel free to drop a comment, until next post! :)