Last active
July 28, 2021 05:47
-
-
Save ishank-katiyar/4a4711300a8bbf4482ab8bb04c3dd444 to your computer and use it in GitHub Desktop.
brute force range update query
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
/** | |
* @param a - initial array | |
* @param query - query array - [li, ri, xi], li and ri are zero-based indexed | |
* @return array after processing all queries | |
*/ | |
vector<int> HandleRangeUpdateQuery (vector<int> a, vector<vector<int>> query) { | |
// brute force method | |
// O(Q * N) slow method | |
for (auto& q: query) { | |
int l = q[0], r = q[1], x = q[2]; | |
for (int i = l; i <= r; i += 1) { | |
a[i] += x; | |
} | |
} | |
return a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment