Ctrl K

Numbered Word Shuffle

Easy
Someone took a phrase made of words separated by single spaces, appended each word's position in the phrase (starting at 1) to its end, and then shuffled the words. The result is the string shuffled. For instance, the phrase Keep it simple could have turned into simple3 Keep1 it2. Restore the original phrase: the words in the right order, without the numbers, separated by single spaces.
Example 1
shuffled='world2 Hello1' → 'Hello world'

The word tagged 1 is "Hello" and the word tagged 2 is "world".

Example 2
shuffled='late3 never4 Better1 than2' → 'Better than late never'

Put the words in order of their tags 1, 2, 3, 4 and drop the digits.

Example 3
shuffled='Go1' → 'Go'
Constraints
  • 2 ≤ len(shuffled) ≤ 200
  • The phrase has 1 to 9 words separated by exactly one space, with no leading or trailing spaces
  • Each word is English letters (lowercase or uppercase) followed by a single digit from 1 to 9
  • The word numbers are exactly 1 through the number of words
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSame Letters, Reshuffled EasyThe Sneaked-In Letter EasyDictionary Words in a Text EasyDrop Adjacent Anagrams EasyTallest-First Roll Call Easy
loading Python…
Input
shuffled='world2 Hello1'
Expected
'Hello world'

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