Asked inGoogle,SWE Intern

Minimum Character Deletion Problem Statement

You have been provided a string STR. Your task is to find and return the minimum number of characters that need to be deleted from STR so that each character's frequency in the string is unique.

Example:

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

The frequency of characters: {a:2, B:2, c:3}. Both 'a' and 'B' have the same frequency of 2. By removing one character, either 'a' or 'B', their frequencies become different resulting in {1, 2, 3}, which are all unique.

Input:

"T" - Number of test cases.
For each test case: A string "STR".

Output:

An integer for each test case, representing the minimum number of deletions required to make all character frequencies in 'STR' unique.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ |STR| ≤ 105
Arindam Manna
1y

Minimum Character Deletion

You are given a string ‘STR’. You need to find and return the minimum number of characters to be deleted from ‘STR’ so that the frequency of each character in the string beco...read more

Help your peers!
Add answer anonymously...
Google SWE 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