• + 0 comments

    O(1) auxiliary space !!! wtf dude What about that "N" sized array you are creating dynamically???

    I don't think this question should need more than O(m) complexity (either space or time wise) Here's my approach:-

    long arrayManipulation(int n, vector> queries) {

    map<int, long> m;
    for(vector<int> i:queries)
    {
        int a=i[0], b=i[1];
        m[a]+=i[2];
        m[b+1]-=i[2];
    }
    long val=0, ans=0;
    for(pair<int, long> p : m)
    {
        val+=p.second;
        ans=max(ans, val);
    }
    return ans;
    

    }