Practice30Create account

A word-and-number arrangement machine, when given an input line of words and numbers, rearranges it in steps. Reading only the numbers, from left to right, the machine finds the leftmost pair of neighbouring numbers standing out of ascending order and makes those two numbers trade the places they stand in. Words never move at all, and the machine stops as soon as the numbers of the line read in ascending order from left to right.
Input: 47 kochi 82 salem 19 thane 55.
Which of the following is Step 2 of the above arrangement?

Competition practiceInput-Output
  • A19 kochi 47 salem 82 thane 55
  • B47 kochi 19 salem 82 thane 55
  • C19 kochi 47 salem 55 thane 82
  • D47 kochi 19 salem 55 thane 82

Step-by-Step Solution

The numbers read 47, 82, 19, 55. The leftmost neighbouring pair out of order is 82 and 19, so Step 1 swaps them: 47 kochi 19 salem 82 thane 55 (numbers 47, 19, 82, 55). Now the leftmost such pair is 47 and 19, so Step 2 swaps them: 19 kochi 47 salem 82 thane 55, the answer. "47 kochi 19 salem 82 thane 55" is Step 1. "19 kochi 47 salem 55 thane 82" is Step 3, the last step. "47 kochi 19 salem 55 thane 82" takes the rightmost out-of-order pair first instead of the leftmost.
Answer: A) 19 kochi 47 salem 82 thane 55

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 having an odd number of elements. In each…A word-and-number arrangement machine, when given an input line of words and two-digit…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.…An arrangement machine works on an input line of words and numbers in steps. In each…