• + 0 comments

    Java Solution:-

        public static long arrayManipulation(int n, List<List<Integer>> queries) {
            // Write your code here
            long max = Long.MIN_VALUE;
            long currentValue = 0L;
    
            long[] list = new long[n];
    
            for (List<Integer> e : queries) {
                final int firstIndex = e.get(0) - 1;
                final int secondIndex = e.get(1) - 1;
                final int value = e.get(2);
                list[firstIndex] += value;
    
                if (secondIndex + 1 < list.length) {
                    list[secondIndex + 1] -= value;
                }
            }
    
            for (Long i : list) {
                currentValue += i;
                if (currentValue > max) {
                    max = currentValue;
                }
            }
            return max;
        }