FastPrepEqual Character Frequencies After At Most One Removal

Equal Character Frequencies After At Most One Removal

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREEN
Learn

Problem statement

Given a lowercase string word, return whether you can make the string perfect by removing at most one character occurrence.

A string is perfect when every distinct character remaining in it occurs the same positive number of times. Removing no character is allowed.

Function

canEqualizeFrequency(word: String) → boolean

Examples

Example 1

word = "abcc"return = true

Remove one c, leaving a, b, and c once each.

Example 2

word = "aazz"return = true

The two present characters already have equal frequency, so use zero removals.

Example 3

word = "abbccc"return = false

The frequencies 1, 2, and 3 cannot all become equal after only one decrement.

Constraints

  • 1 <= word.length <= 100000.
  • word contains only lowercase English letters.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean canEqualizeFrequency(String word) {
    // Write your code here.
}
word"abcc"
expectedtrue
Checking account…