Skip to content

Instantly share code, notes, and snippets.

@ishank-katiyar
Last active July 28, 2021 05:47
Show Gist options
  • Save ishank-katiyar/4a4711300a8bbf4482ab8bb04c3dd444 to your computer and use it in GitHub Desktop.
Save ishank-katiyar/4a4711300a8bbf4482ab8bb04c3dd444 to your computer and use it in GitHub Desktop.
brute force range update query
/**
* @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