code: def top_k_frequent_1(nums, k):
      frequency = {}
  
      # count the frequency of each unique element
      for num in nums:
          if num in frequency:
              frequency[num] += 1
          else:
              frequency[num] = 1
  
      arr = [(frequency[el], el) for el in frequency]
      n = len(arr)
  
      if k > n:
          return [el[1] for el in arr]
      if k < 1:
          return []
  
      heap = PriorityQueue()
      for el in arr:
          # push all elements
          heap.push(el)
          # pop the element with smallest frequency
          if heap.count() > k:
              heap.pop()
  
      # take all elements from the heap
      # no need from K times heap.pop() (K LogK), because we already have the array with data (K)
      return [el.val for el in heap.data]
  
file_path: coding-problems/Arrays/top_k_frequent_elements.py
imports: import heapq
label_desc: Use image node_id 1 for calling a global function with example usage: top_k_frequent_1(nums, k) and returns: unknown, unknown, list