Segmentation Fault in Hackerrank arraymanupulation

  c++, fault

link to question

    long arrayManipulation(long n, vector<vector<int>> queries) {
    long long a[n];
    for(long i=0;i<n;i++)
        a[i]=0;
    for(long c=0;c<(long)queries.size();c++)
        for(long j=queries[c][0];j<=queries[c][1];j++)
            a[j-1]+=queries[c][2];
    long max=LONG_MIN;
    for(long d=0;d<n;d++)
    {
        if(a[d]>max)
            max=a[d];
    }
    return max;
}

it is showing segmentation fault i can’t understand why is it showing so?

Source: Windows Questions C++

LEAVE A COMMENT