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 looks for the leftmost number that stands immediately to the right of a word and has not been moved before, and makes that number and that word trade places. A number moved in this way is never moved again, nothing else in the line shifts, and the machine stops when no such number is left.
Input: 29 haldi 56 jeera methi 73 sarson 41.
How many steps are needed to complete the rearrangement of the above input?

Competition practiceInput-Output
  • A4
  • B2
  • C5
  • D3

Step-by-Step Solution

Only a number that stands immediately to the right of a word can be moved. That is true of 56 (after haldi), 73 (after methi) and 41 (after sarson), but not of 29, which begins the line and has nothing to its left. Step 1: 29 56 haldi jeera methi 73 sarson 41. Step 2: 29 56 haldi jeera 73 methi sarson 41. Step 3: 29 56 haldi jeera 73 methi 41 sarson. So 3 steps. "4" counts 29 as well, though no word stands to its left. "2" misses the swap of 41 with sarson. "5" counts one step per number and per word pair in the line.
Answer: D) 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,…An arrangement machine reorders an input line of words and numbers one step at a time.…An arrangement machine reorders an input line of words and numbers one step at a time.…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,…