input: Write a function to rearrange characters in a string such that no two adjacent characters are the same, removing characters if necessary.
  assert rearrange_chars("aabbcc") == "abc"
  assert rearrange_chars("aaabbb") == "ab"
  assert rearrange_chars("aabb") == "ab"
  assert rearrange_chars("aaa") == "a"
output: def rearrange_chars(s):
      from heapq import heappop, heappush
      from collections import Counter
  
      count = Counter(s)
      max_heap = []
      
      for char, freq in count.items():
          heappush(max_heap, (-freq, char))
      
      prev_char, prev_freq = None, 0
      result = []
      
      while max_heap:
          freq, char = heappop(max_heap)
          result.append(char)
          
          if prev_freq < 0:
              heappush(max_heap, (prev_freq, prev_char))
          
          prev_char, prev_freq = char, freq + 1
      
      if len(result) != len(s):
          return "".join(sorted(set(result)))
      return "".join(result)