1class Solution:2def reorganizeString(self, s: str) -> str:3c = Counter(s) # for counting the distinct element4pq = []5for k,v in c.items(): heapq.heappush(pq,(-v,k)) #multipy by -1 to make max heap6ans = ''7while pq :8c, ch = heapq.heappop(pq)9if ans and ans[-1] == ch:10if not pq: return '' // if heap is empty we cant make the ans return empty string11c2, ch2 = heapq.heappop(pq)12ans += ch213c2 += 114if c2: heapq.heappush(pq,(c2,ch2))15else:16ans += ch17c += 118if c: heapq.heappush(pq,(c,ch))19return ans