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: 47 basil 82 cedar 15 dahlia 63 elm.
In Step 2 of the above arrangement, which element is fifth from the left end?

Competition practiceInput-Output
  • Acedar
  • Bbasil
  • C15
  • D63

Step-by-Step Solution

Basil is the leftmost word throughout. Step 1: 82 is put in front of basil, giving 47 82 basil cedar 15 dahlia 63 elm — note that cedar closes up beside basil, because 82 has been taken from between them. Step 2: the largest number still unshifted is 63, which is put in front of basil, giving 47 82 63 basil cedar 15 dahlia elm. Counting from the left: 47, 82, 63, basil, cedar — so cedar is fifth. Stopping a place short gives basil, running a place past gives 15, and looking at the third place gives 63.
Answer: A) cedar

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