Data Structures & AlgorithmsHardProduct Company SDE · Fenwick round

Problem: What is the complexity of computing the number of inversions using a Fenwick tree over n distinct values?

  1. A. O(n^2)
  2. B. O(n log n)
  3. C. O(n)
  4. D. O(n sqrt n)

Correct answer: B. O(n log n)

Each element costs one Fenwick query and one update, each O(log n).

More Coding Interview Problems questions

Exams that ask this topic