Question: Design a data structure which does the following. solve using Java You have to do all the operations in O(1) time. 1) Inc(Key) -> Takes

Design a data structure which does the following. solve using Java

You have to do all the operations in O(1) time.



1) Inc(Key) -> Takes a key and increment its value by 1. If the key comes first time then make its value as 1.

2) Dec(Key) -> Takes a key and decrement its value by 1. It is given that its value is minimum 1.

3) Findmaxkey() -> Returns the key which has the maximum value corresponding to it. If there are multiple such keys then you can output any of them.

4) Findminkey() -> Returns the key which has the minimum value corresponding to it. If there are multiple such keys then you can output any of them.

Hint: You can also use a dictionary(hashmap) with a doubly-linked list. Dictionary means java.util.Dictionary

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!