PanPey's blog

By PanPey, history, 3 years ago, In English

Given a positive integer N and an array A of size N such that 1 <= Ai <= N. Our aim is to find whether it can be made permutable. i.e each number from 1 to N appears in A exactly once. We perform an operation to do so. In an operation, we can choose any integer and increase its value. Find the minimum number of changes to make the array permutable and print it. If the array is already permutable print 0, -1 if it's not possible.

Consider 3 test cases. First-line contains N. Next line contains an array of size N.

Sample Input
 3 
 4
 1 3 3 4
 5
 1 2 3 5 4
 5
 2 3 2 1 3

Sample Output
 -1
 0
 2 

Full text and comments »

  • Vote: I like it
  • +9
  • Vote: I do not like it