Skip to content

Latest commit

 

History

History

apply-operations-to-make-string-empty

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Apply operations to make string empty

Problem link

Solutions

Solution.py

# https://leetcode.com/problems/apply-operations-to-make-string-empty/

class Solution:
    def lastNonEmptyString(self, s: str) -> str:
        ctr = Counter(s)
        maxct = max(ctr.values())

        last = {}
        for i, x in enumerate(s):
            last[x] = i
        return ''.join(sorted(
            [c for c, v in ctr.items() if v == maxct],
            key=lambda x: last[x]
        ))

Tags