Monday, August 25, 2014

Optym Online Test: Minimize the moves

You have a sequence of d[0] , d[1], d[2] , d[3] ,..,d[n]. In each move you are allowed to increase any d[i] by 1 or 2 or 5  i:0 to n .What is the minimum number of moves required to transform the sequence to permutation of [1,2,3,..,n] if it's possible else return -1. 
Constraint: 1<=n<=1000

Input:
First Line will have no of elemnts
Second Line on. elements will be present
Ex: 5
  1
1
3
2
1

Output:
As no of elements are 5, all permutation can be {1, 2, 3, 4, 5} .
To convert input to get all possible permutation i.e {1, 2, 5, 4, 3},
no of moves will be 4.

Hence output would be 4.

1 comment: