public int[] solution(int n, int[] a) {
        int counters[] = new int[n];
        int maxValue = 0;
        for (int i = 0; i<a.length; i++){
            if (a[i] == n + 1){
               for (int k = 0; k<counters.length; k++){
                   counters[k] = maxValue;
               }
            }
            else{
               int counterIndex = a[i]-1;

                counters[counterIndex] += 1;
                if (counters[counterIndex]>maxValue) maxValue = counters[counterIndex];
            }

        }
        return counters;
    }