Array Operations: Mex Value You are given an array A of N integers and an integer K. You can perform the following opera
Posted: Thu Jul 14, 2022 2:16 pm
Array Operations: Mex Value You are given an array A of N integers and an integer K. You can perform the following operation exactly K times. In a single operation, you can replace any ith element from the array with an integer. Mex of an array is the smallest non-negative integer that is not present in the array. If you perform all K operations optimally, print the maximum Mex of the whole array you can achieve. Note 1. In one operation, you can replace any number by itself too. 2. You can perform such an operation on any element multiple times. Function Description In the provided code snippet, implement the provided getMaxMex (…) method using the variables to print the maximum Mex value of the array. You can write your code in the space below the phrase "WRITE YOUR LOGIC HERE". There will be multiple test cases running, so the Input and Output should match exactly as provided. The base Output variable result is set to a default value of −404 which can be modified. Additionally, you can add or remove these output variables. Input Format The first line contains an integer N. The second line contains N space-separated integers of array A. The third line contains K i.e. exactly K operations to be done.
Input Format The first line contains an integer N. The second line contains N space-separated integers of array A. The third line contains K i.e. exactly K operations to be done. Constraints 1<N<=10∧50<=A<10∧50≪=K<=10∧5 Output Format Output the maximum Mex you can achieve after exactly K operations. Explanation For the given sample test case, there are 5 integers given: 1, 2, 3, 4, 2 and we have to perform exactly 2 operations. Initially, Mex is 0. As 0 is not present in the array, we change 4 to 0 ; our array becomes 1 , 2,3,0,2 and Mex is updated to 4 . In the next operation, we change 2 to 4 ; the array becomes 1, 2, 3,0,4 and our Mex has updated to 5 after 2 operations. 5 is the maximum Mex we can achieve. Hence, the output is 5.
Input Format The first line contains an integer N. The second line contains N space-separated integers of array A. The third line contains K i.e. exactly K operations to be done. Constraints 1<N<=10∧50<=A<10∧50≪=K<=10∧5 Output Format Output the maximum Mex you can achieve after exactly K operations. Explanation For the given sample test case, there are 5 integers given: 1, 2, 3, 4, 2 and we have to perform exactly 2 operations. Initially, Mex is 0. As 0 is not present in the array, we change 4 to 0 ; our array becomes 1 , 2,3,0,2 and Mex is updated to 4 . In the next operation, we change 2 to 4 ; the array becomes 1, 2, 3,0,4 and our Mex has updated to 5 after 2 operations. 5 is the maximum Mex we can achieve. Hence, the output is 5.