CodeMosa

Master LeetCode Patterns

3 Problems

Fenwick Tree (BIT) Practice Problems

Dynamic prefix sums/frequencies and order statistics using a Binary Indexed Tree.

Back to Collections

Relevant Patterns

#
Study these pattern guides before tackling the problems. Understanding the core concepts will help you solve them more efficiently.

Practice Problems

#
Show 2 hints
  • Process from right; query prefix counts of values < current.
  • Coordinate compress values to 1..m.
Hard#493
Show 2 hints
  • Count pairs (i<j, nums[i] > 2*nums[j]) via BIT over compressed values.
  • Alternatively use mergesort counting.
Show 2 hints
  • Cost is min(count < x, count > x); maintain BIT of frequencies.
  • Use modulo arithmetic as required by problem.

Track Your Progress

Mark problems as complete as you solve them. Come back anytime to continue where you left off.