Please help me out with the approach

Revision en1, by PanPey, 2021-05-10 09:16:58

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 

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English PanPey 2021-05-10 09:16:58 691 Initial revision (published)