There are numbers from 1 to n, which are inverted such that
it results in numbers from n to 1. If only two consecutive
numbers are stampled at a time and are inverted, how many
moves are required?



There are numbers from 1 to n, which are inverted such that it results in numbers from n to 1. If ..

Answer / venomvendor

Answer is

Sigma(count), where count ranges from [1 to {n-(swap per time -1)}]

n-(swap per time - 1)
Σ i
i=1

Image Notation >> http://imgur.com/6HkcXzP

In this case.
n = n
swap per time = 2

Substituting this, we get

n-(2 - 1)
Σ i
i=1

n-1
Σ i
i=1

1+2+3+ . . . + (n-1)

if n = 5
Total swaps would be

1+2+3+4 = 10

Is This Answer Correct ?    6 Yes 0 No

Post New Answer

More AI Algorithms Interview Questions

Given a sorted array of n integers that has been rotated i(unknown) number of times, give a (log n) algorithm that finds an element in the array.

0 Answers   Expedia,


Give a general algorithm for converting a m-array tree to a 2-ary tree.

0 Answers   Tech Mahindra,


What is Na?ve Bayes Algorithm?

2 Answers  


Explain the Canny's Algorithm.

0 Answers   Adobe,


What is breadth-first search algorithm?

0 Answers  






Give an example of an O (n) algorithm and O (n*n) algorithm such that the algorithm is slower.

0 Answers   Aspiring Minds,


What is bidirectional search algorithm?

0 Answers  


What is depth-first search algorithm?

0 Answers  


What is breath-first search algorithm?

0 Answers  


Which is the most straight forward approach for planning algorithms?

0 Answers  


Draw a flowchart to find the average of four number?

0 Answers  


What is informed (heuristic) search strategies algorithm?

0 Answers  


Categories