Hello Community, I wanted to have a function to find order of key for an ordered set in java. As far as I know there is no any predefined function to find the number of elements lesser than the given element in an ordered set(treeset) in java in log(n) time? Can some one share their implementation. Thanks !!
You can refer to these blogs: 1, 2, 3
Also, I made a class PBDS_Compressed, which can take values in a fixed range, implemented using the idea of a Segment Tree (I've not used it much, but I don't think there is any problem in the implementation).
Thanks for your reply. The only problem i face with your code is that it limits me to add values in the range [0,n) . I had the constraints for n<=1e5 and for arr[i]<=1e9. So do you have any other template for this? Basically i want to use this in this leetcode problem : https://leetcode.com/contest/weekly-contest-387/problems/distribute-elements-into-two-arrays-ii/
This is why there is compressed in the name. In case our range is large, we have to do coordinate compression.
Also that problem can be solved using Fenwick Tree (as mentioned in the 1st blog).