Question: I'm developing a cross-platform C++11 application and I need to send a validation email to a user-entered address to make sure his email account exists and is valid.

I know there are temporary mail services like *mailinator*, but honestly I feel like a validation email is a good approach in my case since it gives people malicious intention more work to do to circumvent the system and also goes well with the rest of the application (example: having the email address allow me to automatically send status updates to users).

I have searched on the internet but I haven't been able to find a **portable**, **cross-platform** way to achieve this, at least without introducing big dependencies.

How can this issue be solved?

Answer: 
My **java** solution with a **detailed explanation** 100% Correctness, 100% Performance :

Time Complexity *O(N+M)*

```
 public static int[] solution(int N, int[] A) {

    int[] counters = new int[N];
    //The Max value between all counters at a given time
    int max = 0;

    //The base Max that all counter should have after the "max counter" operation happens
    int baseMax = 0;

    for (int i = 0; i < A.length; i++) {

        //max counter Operation ==> updating the baseMax
        if (A[i] > N) {
            // Set The Base Max that all counters should have
            baseMax = max;

        }

        //Verify if the value is bigger than the last baseMax because at any time a "max counter" operation can happen and the counter should have the max value
        if (A[i] <= N && counters[A[i] - 1] < baseMax) {
            counters[A[i] - 1] = baseMax;
        }

        //increase(X) Operation => increase the counter value
        if (A[i] <= N) {
            counters[A[i] - 1] = counters[A[i] - 1] + 1;

            //Update the max
            max = Math.max(counters[A[i] - 1], max);
        }
    }

    //Set The remaining values to the baseMax as not all counters are guaranteed to be affected by an increase(X) operation in "counters[A[i] - 1] = baseMax;"
    for (int j = 0; j < N; j++) {
        if (counters[j] < baseMax)
            counters[j] = baseMax;
    }

    return counters;
}

```
Typescript:

```
function counters(numCounters: number, operations: number[]) {
const counters = Array(numCounters)

let max = 0
let currentMin = 0

for (const operation of operations) {
    if (operation === numCounters + 1) {
        currentMin = max
    } else {
        if (!counters[operation - 1] || counters[operation - 1] < currentMin) {
            counters[operation - 1] = currentMin
        }

        counters[operation - 1] = counters[operation - 1] + 1

        if (counters[operation - 1] > max) {
            max += 1
        }
    }
}

for (let i = 0; i < numCounters; i++) {
    if (!counters[i] || counters[i] < currentMin) {
        counters[i] = currentMin
    }
}

return counters

```

}

console.log(`solution=${counters(5, [3, 4, 4, 6, 1, 4, 4])}`)