• + 1 comment

    Java working solution, with some test cases are failing because of "time limit exceed"

    #########################################################################

    public static long arrayManipulation(int n, List> queries) { int row=queries.size(); int col=queries.get(0).size(); //array to hold final combine result from row:0 to row:n long[] arr = new long[n]; long max=0, currMax=0;

        for(int i=0; i<row; i++) {
            int start=queries.get(i).get(0);
            int end=queries.get(i).get(1);
            int val=queries.get(i).get(2);
    
            for(int j=start-1; j<end; j++) {
                arr[j]=arr[j]+val;
                if(arr[j]>currMax){
                    currMax=arr[j];
                }
            }
            if(currMax>max){
                max=currMax;
            }
        }
        return max;
    }
    
    #
    • + 0 comments

      https://www.hackerrank.com/challenges/crush/forum/comments/1502854