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: 
```
vector<int> solution(int N, vector<int> &A)
{
    std::vector<int> counters(N);
    auto max = 0;
    auto current = 0;

    for (auto& counter : A)
    {
        if (counter >= 1 && counter <= N)
        {
            if (counters[counter-1] < max)
                counters[counter - 1] = max;

            counters[counter - 1] += 1;

            if (counters[counter - 1] > current)
                current = counters[counter - 1];
        }
        else if (counter > N)
            max = current;

    }

    for (auto&& counter : counters)
        if (counter < max)
            counter = max;

    return counters;
}

```
100%, O(m+n)

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

    int[] counters = new int[N];
    int maxAIs = 0;
    int minAShouldBe = 0;

    for(int x : A) {
        if(x >= 1 && x <= N) {
            if(counters[x-1] < minAShouldBe) {
                counters[x-1] = minAShouldBe;
            }

            counters[x-1]++;

            if(counters[x-1] > maxAIs) {
                maxAIs = counters[x-1];
            }
        } else if(x == N+1) {
            minAShouldBe = maxAIs;
        }
    }

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

    return counters;
}

```