Practice30Create account

A word-and-number arrangement machine, when given an input line of words and numbers, rearranges it in steps. Only the second letter of a word matters to this machine. In each step it looks over the words still waiting, picks the one whose second letter stands nearest the beginning of the alphabet, and moves that word to the extreme right end of the line. Should two waiting words carry the same second letter, whichever of them stood nearer the right-hand end of the input goes first. Nothing else changes place, and the machine halts when no word is left waiting.
Input: 38 orchid 92 anvil 15 elder 74 spruce.
At which step of the above arrangement does the line "38 orchid 92 15 74 elder anvil spruce" appear?

Competition practiceInput-Output
  • AStep 2
  • BStep 4
  • CStep 3
  • DStep 1

Step-by-Step Solution

Second letters: elder gives l, anvil gives n, spruce gives p, orchid gives r, so the words leave in that order. Step 1: 38 orchid 92 anvil 15 74 spruce elder. Step 2: 38 orchid 92 15 74 spruce elder anvil. Step 3: 38 orchid 92 15 74 elder anvil spruce — the line asked about. Step 4, the last, would be 38 92 15 74 elder anvil spruce orchid. Orchid is still standing among the numbers here, so exactly one word remains to be shifted and this cannot be the last step.
Answer: C) Step 3

Master this topic in 30 minutes a day.

Don't just memorise the answer — build a daily practice habit.

Practice 5 Similar Questions Free →

All Input-Output practice questions

More Input-Output practice

A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…A word-and-number arrangement machine, when given an input line of words and numbers,…