Missing Number

You are given an array A. You can decrement any element of the array by 1. This operation can be repeated any number of times. A number is said to be missing if it is the smallest positive number which is a multiple of 2 that is not present in array A. You have to find the maximum missing number after all possible decrements of the elements.

Example:

Input:  n = 6, a = [1 3 3 3 6 7]
Output: 8

Approach

C++

#include <bits/stdc++.h>
using namespace std;

long long missingNumbers(long long nlong long a[])
{
    sort(aa + n);
    long long res = 2;
    for (long long i = 0i < ni++)
    {
        if (a[i] >= res)
            res += 2;
    }
    return res;
}
int main()
{
    long long n = 6;

    long long a[n] = {133367};

    cout << missingNumbers(na<< "\n";

    return 0;
}


No comments:

Post a Comment