105Fenwick tree (Binary Indexed Tree): point updates and prefix sums in O(log n).▼mediumGoogleMetaAmazon2 replies◆ premiumA Fenwick tree serves prefix-sum queries and point updates in O(log n) using one flat array and a single bit trick. The signal is the lowbit operation and why it wins over a plain prefix array when values change. Here is the answer.Open full answer →
106Segment tree: range queries and point updates for sum, min, or max in O(log n).▼hardGoogleMetaAmazon2 replies◆ premiumA segment tree serves any associative range query (sum, min, max, gcd) with point or range updates in O(log n). The signal is the recursive split into covered, disjoint, and partial nodes, plus lazy propagation for range updates. Here is the answer.Open full answer →