Equal Character Frequencies After Removal

TCS NQT Coding Easy Go Ad-Free - ₹20/mo

Given a string consisting of lowercase English letters, determine if it is possible to remove exactly one character so that the frequency of each remaining character is the same. Return true if such a removal is possible, otherwise false.

Examples:

Input: 'yummy'

Output: true

Explanation: After removing 'u', the string becomes 'yymm' with frequencies: y:2, m:2, which are the same.

Input: 'stop'

Output: true

Explanation: All characters initially have frequency 1. After removing any one character, the remaining characters still have frequency 1.

Input: 'aabb'

Output: false

Explanation: Frequencies are a:2, b:2. Removing any one character results in frequencies a:2,b:1 or a:1,b:2, which are not the same.

Constraints

  • 2 <= length of string <= 1000
  • String contains only lowercase English letters.