This question was the 3rd amongst the 3 questions in the online Hackwithinfy round 2 on 31st May 2020. This was worth 100 points (of total 225 points).
I was not able to solve this.
You are given an array A consisting of N integers. The number of integers N is even. You can perform the following 2 operations:-
You want to delete all the elements of A. What is the minimum number of operations that must be performed?
Input: A = [1, 2, 4, 3], N = 4
Output: 5
Explanation:
We increase A2 and A3 by 1. [2 operations]
A = [1, 3, 5, 3]
Remove A2 and A3 as they are consecutive primes [1 operation]
A = [1, 3]
Increase A1 by 1 [1 operation]
A = [2, 3]
Remove A1 and A2 as they are consecutive primes. [1 operation]
Total operations = 5