human
I found an interesting problem on https://leetcode.com/problems/all-oone-data-structure/:
Implement a data structure supporting the following operations:


Inc(Key) - Inserts a new key  with value 1. Or increments an existing key by 1. Key is guaranteed to be a non-empty string.
Dec(Key) - If Key's value is 1, remove it from the data structure. Otherwise decrements an existing key by 1. If the key does not exist, this function does nothing. Key is guaranteed to be a non-empty string.
GetMaxKey() - Returns one of the keys with maximal value. If no element exists, return an empty string "".
GetMinKey() - Returns one of the keys with minimal value. If no element exists, return an empty string "".



Challenge: Perform all these in O(1) time complexity.

I tried it in Python, but could not do it. Can you solve it?

Give me a the Python code you requested?
assistant
#Here is the Python code you requested.

 class Node:
     def __init__(self, cnt):
         self.count = cnt
         self.prev = None
         self.next = None
 
 
 class AllOne(object):
 
     def __init__(self):
         """
         Initialize your data structure here.
         """
         #Key:count, Value:set of key who has been incremented by 'count' time
         self.count_key_map = {}
         #Key:key, Value: the number of counts of this key
         self.key_count_map = {}
         #Key: the count, Value: the node
         self.count_node_map = {}
         
         #initialize the linkedlist with dummy node
         self.head = Node(0)
         self.tail = Node(float('inf'))
         self.head.next = self.tail
         self.tail.prev = self.head
         
         self.count_node_map[0] = self.head
         self.count_node_map[float('inf')] = self.tail
 
     def inc(self, key):
         """
         Inserts a new key <Key> with value 1. Or increments an existing key by 1.
         :type key: str
         :rtype: void
         """
         if key not in self.key_count_map:
             self.key_count_map[key]=0
         
         
         prev_count=self.key_count_map[key]
         prev_node=self.count_node_map[prev_count]
         
         self.key_count_map[key]+=1
         
         if prev_node.next.count!=self.key_count_map[key]:
             new_node=Node(self.key_count_map[key])
             self.insert(prev_node,new_node)
             self.count_key_map[self.key_count_map[key]]=set()
             self.count_node_map[self.key_count_map[key]]=new_node
         
         self.count_key_map[self.key_count_map[key]].add(key)
         
         if prev_count!=0:
            
            self.count_key_map[prev_count].remove(key)
            if len(self.count_key_map[prev_count])==0:
                self.count_node_map.pop(prev_count)
                self.count_key_map.pop(prev_count)
                self.delete(prev_node)
                
     
         
 
     def dec(self, key):
         """
         Decrements an existing key...