input: Write a python function to encode text using Huffman encoding.
  assert HuffmanEncode("hello") == '011011110011'
  assert HuffmanEncode("test") == '1100111000'
  assert HuffmanEncode("aabbcc") == '001100110011'
output: import heapq
  from collections import defaultdict, Counter
  
  def HuffmanEncode(text):
      if not text:
          return ""
  
      # Build frequency dictionary
      frequency = Counter(text)
      
      # Create a priority queue with nodes
      heap = [[weight, [char, ""]] for char, weight in frequency.items()]
      heapq.heapify(heap)
      
      while len(heap) > 1:
          lo = heapq.heappop(heap)
          hi = heapq.heappop(heap)
          for pair in lo[1:]:
              pair[1] = '0' + pair[1]
          for pair in hi[1:]:
              pair[1] = '1' + pair[1]
          heapq.heappush(heap, [lo[0] + hi[0]] + lo[1:] + hi[1:])
      
      # Build Huffman encoding map
      huffman_map = sorted(heapq.heappop(heap)[1:], key=lambda p: (len(p[-1]), p))
      huffman_dict = {char: code for char, code in huffman_map}
      
      # Encode the text
      encoded_text = ''.join(huffman_dict[char] for char in text)
      return encoded_text