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;
}

```
Here is solution in python with 100 % 
[Codility Max counter 100%](https://app.codility.com/demo/results/trainingUQ95SB-4GA/) 

```
def solution(N, A):
"""
Solution at 100% - https://app.codility.com/demo/results/trainingUQ95SB-4GA/
Idea is first take the counter array of given size N
take item from main A one by one + 1 and put in counter array , use item as index
keep track of last max operation
at the end replace counter items with max of local or counter item it self
:param N:
:param A:
:return:
"""
global_max = 0
local_max = 0
# counter array
counter = [0] * N

for i, item in enumerate(A):
    # take item from original array one by one - 1 - minus due to using item as index
    item_as_counter_index = item - 1
    # print(item_as_counter_index)
    # print(counter)
    # print(local_max)
    # current element less or equal value in array and greater than 1
    #         if A[K] = X, such that 1 ≤ X ≤ N, then operation K is increase(X),
    if N >= item >= 1:
        # max of local_max counter at item_as_counter_index
        # increase counter array value and put in counter array
        counter[item_as_counter_index] = max(local_max, counter[item_as_counter_index]) + 1
        # track the status of global_max counter so far
        # this is operation K
        global_max = max(global_max, counter[item_as_counter_index])
    #         if A[K] = N + 1 then operation K is max counter.
    elif item == N + 1:
        # now operation k is as local max
        # here we need to replace all items in array with this global max
        # we can do using for loop for array length but that will cost bigo n2 complexity
        # example -  for i, item in A: counter[i] = global_max
        local_max = global_max
    # print("global_max each step")
    # print(global_max)

# print("local max so far....")
# print(local_max)
# print("counter - ")
# print(counter)
# now counter array - replace all elements which are less than the local max found so far
# all counters are set to the maximum value of any counter
for i, item in enumerate(counter):
    counter[i] = max(item, local_max)

return counter

```

result = solution(1, [3, 4, 4, 6, 1, 4, 4])
print("Sol " + str(result))