noobied's blog

By noobied, history, 2 years ago, In English

How can i implement a Multiset in java which has all functions of treeset such as higher(),lower(),ceiling(),floor() etc. Is there is any way?

 
 
 
 
  • Vote: I like it
  • -2
  • Vote: I do not like it

»
2 years ago, # |
  Vote: I like it +14 Vote: I do not like it
  1. TreeMap<Key, Count>
  2. TreeSet<Pair<Key, Index>>
  • »
    »
    2 years ago, # ^ |
    Rev. 3   Vote: I like it 0 Vote: I do not like it

    Thanks dalex really helpfull

  • »
    »
    2 years ago, # ^ |
    Rev. 5   Vote: I like it 0 Vote: I do not like it
    Code

    We just need to do this right? or should i also include hasCode in the pair class too

  • »
    »
    6 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can we get min and max keys from TreeMap in better than O(n) time? If yes, how?

    • »
      »
      »
      6 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      Yes of course, take a look at the jdk manual of the TreeMap class, if I remember correctly it's firstKey() and lastKey() (not to sure, check it out).

»
2 years ago, # |
  Vote: I like it +17 Vote: I do not like it

multitreeset class i wrote a long time ago https://ideone.com/IxJk23

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    thanks now i understand how to create multiset

  • »
    »
    2 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    you are the most hated person on hackerrank community LOL

»
23 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

In case it helps anyone, I implemented MultiSet here and Ordered MultiSet here in Java.

Let me know if you find any mistakes. Suggestions are always welcomed.