bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 1647. Minimum Deletions to Make Character Frequencies Unique

1647. Minimum Deletions to Make Character Frequencies Unique

Leetcode Solutions

Sorting Frequencies and Adjusting to Unique Values

  1. Initialize an array frequency of size 26 to store the frequency of each character (since there are 26 lowercase English letters).
  2. Iterate over the string s and increment the frequency count for each character.
  3. Sort the frequency array in descending order.
  4. Initialize maxFreqAllowed to the length of s (the maximum possible frequency).
  5. Initialize deleteCount to 0 (the count of deletions made).
  6. Iterate over the sorted frequency array:
    • If frequency[i] is greater than maxFreqAllowed, increment deleteCount by frequency[i] - maxFreqAllowed.
    • Set frequency[i] to maxFreqAllowed.
    • Decrement maxFreqAllowed by 1, ensuring it does not go below 0.
  7. Return deleteCount.
UML Thumbnail

Decrement Each Duplicate Until it is Unique

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...
bugfree Icon
OR