A marching band lines up in a temporary holding order before the final formation. Each performer carries a placard printed with a single lowercase letter, and the show director hands every performer a slot number: the position they must occupy once the band moves into its final row. Given the placards in holding order and each performer's assigned slot, determine the string of letters that the placards spell out once every performer has moved into their assigned slot.
n, the number of performers.s of length n -- the placard letters in holding order.n space-separated integers indices[0..n-1] -- the final slot assigned to the performer holding s[i].A single line containing the string formed by placing each character s[i] at position indices[i] in the final row (0-indexed).
s consists only of lowercase English letters, and its length equals n.indices is a permutation of the integers 0 through n-1.Example 1
Input
8 codeleet 4 5 6 7 0 2 1 3
Expected
leetcode
Explanation
Performer 0 holds 'c' and moves to slot 4, performer 1 ('o') to slot 5, performer 2 ('d') to slot 6, performer 3 ('e') to slot 7, performer 4 ('l') to slot 0, performer 5 ('e') to slot 2, performer 6 ('e') to slot 1, and performer 7 ('t') to slot 3. Reading slots 0 through 7 in order gives l, e, e, t, c, o, d, e, which spells "leetcode".
Example 2
Input
3 abc 0 1 2
Expected
abc
Explanation
Every performer is already assigned to their current slot (the identity permutation 0, 1, 2), so the formation string is unchanged: "abc".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →