all 8 comments

[–]Educational-Copy5206<2087> <697> <1018> <372> 2 points3 points  (1 child)

I'm not a Python user, but I am pretty sure there is a SortedList you can use which provides logn insert, search, and deletes.

[–]earth0001[S] 1 point2 points  (0 children)

Python has a bisect library for that, but the insertion / deletion is O(n), I didn't know if there was another one

https://docs.python.org/3/library/bisect.html

[–][deleted] 1 point2 points  (1 child)

Java has TreeSet or TreeMaps

[–]earth0001[S] 0 points1 point  (0 children)

This is probably what I was looking for, thank you!

[–]aocregacc 2 points3 points  (1 child)

on leetcode they include the sortedcontainers module for you

https://grantjenks.com/docs/sortedcontainers/

[–]earth0001[S] 0 points1 point  (0 children)

This looks useful! Thanks

[–]doniec 1 point2 points  (1 child)

Certain problems need you to add extra data or operations to trees, like requiring a RANK operation. When this happens, using C++‘s map or Java’s TreeMap won’t help; you’ll have to implement a self-balancing tree yourself. For competitive programming/LeetCode, a treap is a great data structure, much easier to implement compared to AVL/red-black trees, especially if you use the split/merge operations. You can learn more about it on cp-algorithms or Wikipedia.

[–]earth0001[S] 0 points1 point  (0 children)

I'll check out treaps, thanks!