Ctrl K

Letters to Their Places

Easy
You are given a string jumbled and a list targets of the same length n. The numbers in targets are a permutation of 0 to n - 1. The letter at position i of jumbled belongs at position targets[i]. Put every letter in its place and return the resulting string.
Example 1
jumbled='tac', targets=[2, 1, 0] → 'cat'

t moves to position 2, a stays at 1 and c goes to 0, giving "cat".

Example 2
jumbled='ilkm', targets=[1, 2, 3, 0] → 'milk'

Each of the first three letters moves one place to the right and m goes to the front, giving "milk".

Constraints
  • 1 ≤ n ≤ 100
  • len(targets) = len(jumbled) = n
  • jumbled consists of lowercase English letters
  • 0 ≤ targets[i] < n, and all values are distinct
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsTwo Words, Closest Apart EasyOne-Row Typing EasyDinner for Two EasyPhrases with Synonyms EasyWord from a License Plate Easy
loading Python…
Input
jumbled='tac', targets=[2, 1, 0]
Expected
'cat'

Run checks the first 3 tests in your browser. Submit checks all 61 tests on the server, hidden ones included.