Frequency counting for a linear-time algorithm
Frequency counting is a powerful technique in algorithms design. It comes often when we're dealing with a small subset of data, such as lower-case alphabet letters. The problem below exemplifies it. Instead of removing characters one by one, the idea is to do a frequency counting and subsequently create the final string based on the max frequency. Code is down below, cheers, ACC. Apply Operations to Make String Empty - LeetCode 3039. Apply Operations to Make String Empty Medium 32 4 Add to List Share You are given a string s . Consider performing the following operation until s becomes empty : For every alphabet character from 'a' to 'z' , remove the first occurrence of that character in s (if it exists). For example, let initially s = "aabcbbca" . We do the following operations: Remove the underlined characters s = " a a bc bbca" . The resulting string is s = "abbca" . Remove the underl...