Unique Frequency Problem Statement

Given a string 'STR' with lowercase letters, determine the minimum number of deletions required to ensure that every letter in the string appears a unique number of times.

Example:

Input:
S = "aaBBccc"
Output:
1
Explanation:

The frequencies of the characters are {a:2, B:2, c:3}. Deleting one character from 'a' or 'B' adjusts the frequency so each is unique, resulting in frequencies 1, 2, and 3.

Input:

The first line of input contains a single integer 'T', denoting the number of test cases.
The first line of each test case contains a string 'STR'.

Output:

For each test case, print an integer indicating the minimum number of characters to delete such that each character frequency is unique.

Constraints:

  • 1 <= T <= 10
  • 1 <= |STR| <= 105
  • Time limit: 1 sec
Note:

You are not required to print the output; it has already been taken care of. Implement the function accordingly.

AnswerBot
3d

The task is to find the minimum number of deletions needed in a string to ensure each character appears a unique number of times.

  • Iterate through the string and count the frequency of each character

  • Tra...read more

Help your peers!
Add answer anonymously...
American Express Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter