Sort by

recency

|

2494 Discussions

|

  • + 0 comments

    TypeScript

    function arrayManipulation(n: number, queries: number[][]): number {
        const result = new Array(n + 1).fill(0);
        for (const [start, end, value] of queries) {
            result[start - 1] += value;
            if (end < n) {
                result[end] -= value;
            }
        }
        let max = 0;
        let currentSum = 0;
        for (let i = 0; i < n; ++i) {
            currentSum += result[i];
            max = Math.max(max, currentSum);
        }
        return max;
    }
    
  • + 1 comment

    Could someone clarify what the question means? Either it’s not well-worded, or my understanding is lacking, and I'm feeling confused.

  • + 2 comments

    What in the world is this problem asking? Seems poorly defined IMO

  • + 0 comments

    I have used in Prefix method

    long [] arr= new long[n+2];

     for (List<Integer> q: queries){
        int a= q.get(0);
        int b=q.get(1);
        int k=q.get(2);
    
         arr [a] +=k;
         arr [b+1] -=k;
         }
         long max=0,current=0;
         for(int i =1; i<=n;i++){
            current += arr[i];
            if(current > max){
                max = current;
            }
         }
         return max;
         }
    

    }

  • + 0 comments

    import sys queries=sys.stdin.read().strip().split() it=iter(queries) n=int(next(it)) q=int(next(it)) arr = [0] * (n+2)

    for i in range(q): a = int(next(it)) b = int(next(it)) k = int(next(it)) arr[ a ] += k arr[ b +1] -= k

    max_value = 0 current = 0 for val in arr: current += val max_value = max(max_value, current)

    print(max_value)