0

I am having a hard time in solving a variant of Leetcode 307 Range Sum Query - Mutable and Leetcode 528: Random Pick with Index such that to design a data structure so that I can add elements and each element will has a weight and pop elements based proportional to weights. I am thinking about the optimal complexity of add and pop operation to be o(log n ) where n is the existing data size. However, I could find a good algorithm/data structure to solve it.

Lala James
  • 33
  • 4

1 Answers1

0

Splay Tree(or other Self-Balancing BST) would supports insertion/deletion at arbitrary position, range sum query, and also lower_bound/upper_bound in amortized O(lgn).

Chad
  • 23
  • 4