This is a verified interview question from Zinnia. Candidates reporting seeing this problem in recent Online Assessments (OAs) and onsite rounds. Mastering "Minimum steps" covers key patterns like Other.
"### Problem Given an array A consisting of positive integers. You have to convert each integer number in the array to some prime number. In each step, you can select any index of the array and decrease or increase the array element present at the selected index by 1. Find the minimum number of steps needed to convert each element of the array to some prime number. ### Function description Complete the solve function. The function takes the following 2 parameters and returns the minimum number of steps required to convert all array elements to prime numbers: * N: Represents the number of elements in the array * A: Represents the elements of the array ### Input format for custom testing Note: Use this input format if you are testing against custom input or writing code in a language where we don't provide boilerplate code. * The first line contains a single integer N denoting the length of the array * The second line contains N space-separated integers denoting the elements of the array ### Constraints - 1 ≤ N ≤ 10^5 - 1 < A_i < 10000000 ### Output format Print an integer representing the minimum number of steps to convert each element of the array to some prime number. ### Test Cases #### Sample input 4 9 5 5 6 #### Sample output 3 ### Explanation In sample, two 5s are already primes. You don't need to change them, for 9, you can either make 7 or 11, both takes 2 steps. And, if you can change 6 to either 5 or 7, both takes 1 step. So, as a whole it takes 3 steps to make all elements prime."
Join thousands of developers practicing for Zinnia.