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 series of positive integers. Design an efficient algorithm that can detect pairs whose sum is equal to K such that K = ei + ej, and (i not equal to j).

0 Answers   Expedia,


What are disadvantages uniform cost search algorithm?

0 Answers  


When an algorithm is considered completed?

0 Answers  


what is software cycle?give a diagramatic representation

0 Answers  


Give an algorithm for the following problem. Given a list of n distinct positive integers, partition the list into two sublists, each of size n/2, such that the difference between the sums of the integers in the two sublists is minimized. You may assume that n is a multiple of 2.

0 Answers  






Explain the Canny's Algorithm.

0 Answers   Adobe,


What features would you use to build a recommendation algorithm for users?

0 Answers   Twitter,


Which search algorithm will use a limited amount of memory in online search?

0 Answers  


Tell me how do you choose an algorithm for a classification problem?

0 Answers  


What is greedy best first search algorithm?

0 Answers  


A lot of questions were asked on sorting for eg. Best algorithm on the basis of number of swaps, number of comparisons etc.

0 Answers   DELL,


What is breadth-first search algorithm?

0 Answers  


Categories