Skip to main content

๐ŸŽฎ Segment/Fenwick (Practice)

Companion to the Segment Tree & Fenwick Tree guide. Build a Fenwick tree (BIT) for O(log n) prefix sums with updates. Edit and run the code right here โ€” it executes in your browser.

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Add a range-sum query(l, r) using two prefix queries.
  2. What does i & (-i) compute, and why?
  3. When is a segment tree preferable to a Fenwick tree?

Continue the learning path โ†’ Backtracking