Created
January 29, 2019 08:33
-
-
Save kkabdol/75e75426e5d659e78da317bb522ae0f2 to your computer and use it in GitHub Desktop.
Array Manipulation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// problem : https://www.hackerrank.com/challenges/crush/problem | |
// solution : https://www.hackerrank.com/challenges/crush/forum | |
long arrayManipulation(int n, vector<vector<int>> queries) { | |
vector<long> arr( n + 1, 0 ); | |
for( auto q : queries ) | |
{ | |
arr[ q[0] ] += q[2]; | |
if( q[1] + 1 <= n ) | |
{ | |
arr[ q[1] + 1 ] -= q[2]; | |
} | |
} | |
long maxK = 0, accK = 0; | |
for( auto k : arr ) | |
{ | |
accK += k; | |
if( accK > maxK ) | |
{ | |
maxK = accK; | |
} | |
} | |
return maxK; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment