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: 
The problem is that when you get lots of `max_counter` operations you get lots of calls to `Arrays.fill` which makes your solution slow.

You should keep a `currentMax` and a `currentMin`:

* When you get a `max_counter` you just set `currentMin = currentMax`.
* If you get another value, let's call it `i`:
	+ If the value at position `i - 1` is smaller or equal to `currentMin` you set it to `currentMin + 1`.
	+ Otherwise you increment it.

At the end just go through the counters array again and set everything less than `currentMin` to `currentMin`.
Using applyMax to record max operations

Time complexity:
O(N + M)

```
class Solution {
    public int[] solution(int N, int[] A) {
        // write your code in Java SE 8

        int max = 0, applyMax = 0;;
        int[] result = new int[N];

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

            if (a == N + 1) {
                applyMax = max;
            }

            if (1 <= a && a <= N) {
                result[A[i] - 1] = Math.max(applyMax, result[A[i] - 1]);
                max = Math.max(max, ++result[A[i] - 1]);
            }
        }

        for (int i = 0; i < N; ++i) {
            if (result[i] < applyMax) {
                result[i] = applyMax;
            }
        }

        return result;
    }
}

```