• + 0 comments

    My solution was similar but taking a bit less space. I think yours is not O(1) it is more like O(N) :-) So you are allocating up to 10MB.. I just used a map instead.

    long arrayManipulation(int n, vector<vector<int>> &queries) {
        map<long,long> changes;
        for (auto &q : queries) {
            changes[q[0]] += q[2];
            changes[q[1]+1] -= q[2];
        }
        long max=0, cur=0;
        for (auto &e : changes) {
            cur += e.second;
            if (cur > max)
                max = cur;
        }
        return max;
    }