View difference between Paste ID: JtS3tP87 and QTYahtWX
SHOW: | | - or go back to the newest paste.
1
// you can also use imports, for example:
2
// import java.util.*;
3
4
// you can write to stdout for debugging purposes, e.g.
5
// System.out.println("this is a debug message");
6
7
class Solution {
8
    int maxElement = 0;
9
    int currentMax = 0;
10
    public int[] solution(int N, int[] A) {
11
        int[] result = new int[N];
12
        for(int i = 0; i < A.length; i++) {
13-
                result = increase(A[i], result);
13+
14-
            maxElement = Math.max(result[A[i]-1], maxElement);
14+
                increase(A[i], result);
15
                maxElement = Math.max(result[A[i]-1], maxElement);
16-
                maxCounter(result);
16+
17
                currnetMax = maxElement;
18
            }
19-
    return result;
19+
20
        for(int i = 0; i < result.length; i++) {
21-
    public int[] increase(int i, int[] j) {
21+
             result[i] = Math.max(result[i], currentMax);
22-
        j[i-1] += 1;
22+
23-
        return j;
23+
        return result;
24
    }
25-
 
25+
    public void increase(int i, int[] j) {
26-
    public int[] maxCounter(int[] j) {
26+
        j[i-1] = currentMax + j[i-1] + 1;
27-
        for(int z = 0; z < j.length; z++) {
27+
28-
            j[z] = maxElement;
28+
29