Practice30Create account

An arrangement machine reorders an input line of words and numbers one step at a time. Every step moves two words at once — whichever word still in place is longest travels to the far left, and whichever is shortest travels to the far right. Numbers never move, every other element holds its relative position, and the machine halts once every word has moved.
Input: harvest 39 neem 54 banyan 26 tulsi.
In the last step of the above arrangement, which element is fifth from the left end?

Competition practiceInput-Output
  • A26
  • B54
  • Cneem
  • D39

Step-by-Step Solution

The words are harvest (7), neem (4), banyan (6) and tulsi (5). Step 1 sends harvest left and neem right: harvest 39 54 banyan 26 tulsi neem. Step 2, the last, sends banyan left and tulsi right: banyan harvest 39 54 26 neem tulsi. Counting from the left — banyan, harvest, 39, 54, 26 — the fifth element is 26. "54" is fourth from the left. "neem" is sixth. "39" is third, the count made on the input line rather than on the last step.
Answer: A) 26

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

An arrangement machine works on an input line of words and numbers in steps. In each…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,…