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 machine picks the largest number standing in the part of the line that is not yet fixed, and makes it trade places with whatever element occupies the first position of that not-yet-fixed part; that position then becomes fixed. Nothing else moves — the two elements simply interchange — and the machine stops once every number has been fixed.
Input: 27 basil 56 clove 83 dill 41 elm.
In Step 3 of the above arrangement, which element is second from the right end?

Competition practiceInput-Output
  • Aelm
  • Bdill
  • C56
  • Dbasil

Step-by-Step Solution

Step 1: 83 is the largest number and 27 heads the line, so they interchange: 83 basil 56 clove 27 dill 41 elm. Step 2: the largest loose number is 56 and the first unfixed position is 2, held by basil, so those two trade: 83 56 basil clove 27 dill 41 elm — notice basil has been flung into the slot 56 left. Step 3: the largest loose number is now 41 and the first unfixed position is 3, held by basil again, so they trade: 83 56 41 clove 27 dill basil elm. Counting from the right: elm, basil — so basil is second. Taking the very last element gives elm and going one place further gives dill, while counting from the left end instead gives 56.
Answer: D) basil

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