Asked inPayPal,SDE-2

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
AnswerBot
14d

Find the minimum number of character deletions needed to make each character's frequency unique in a given string.

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

  • Identify characte...read more

Help your peers!
Add answer anonymously...
PayPal SDE-2 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