Skip to content

Instantly share code, notes, and snippets.

@ishank-katiyar
ishank-katiyar / difference_array.cpp
Last active July 28, 2021 05:47
difference array technique implementation
/**
* @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) {
// creating another array to handle queries
vector<int> b (a.size() + 1, 0);
for (auto& q : query) {
@ishank-katiyar
ishank-katiyar / brute_range_update.cpp
Last active July 28, 2021 05:47
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];