Practice30Create account

A word-and-number arrangement machine, when given an input line of words and numbers, rearranges it in steps. In each step the largest number that has not already been shifted is taken out of the line and put back immediately to the left of whichever word then stands furthest to the left. The rest of the line is left exactly as it stands, and the machine finishes when no unshifted number is left.
Input: 52 opal 38 pine 91 quartz 24.
Which of the following is the last step of the above arrangement?

Competition practiceInput-Output
  • A24 38 52 91 opal pine quartz
  • B91 52 38 24 opal pine quartz
  • Copal pine quartz 91 52 38 24
  • D91 52 38 24 quartz pine opal

Step-by-Step Solution

Opal is the leftmost word at every stage. Step 1: 91 goes in front of opal, giving 52 91 opal 38 pine quartz 24. Step 2: 52 is lifted from the head and put in front of opal, giving 91 52 opal 38 pine quartz 24. Step 3: 38 joins them, giving 91 52 38 opal pine quartz 24. Step 4: 24 joins them, giving 91 52 38 24 opal pine quartz. The numbers finish in descending order because the largest was placed first and each later one is inserted to its right, hard against the word. A machine that threw each number to the extreme left end would have finished the other way round, 24 38 52 91, which is the first line. The third line sends the numbers to the right end instead, and the fourth reverses the words, which never move.
Answer: B) 91 52 38 24 opal pine quartz

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,…