Show problems as
Classic problem #2423EasyHash TableStringCounting

Remove Letter To Equalize Frequency

Real-world version: Pull One Stem to Even the Bunch
Tracked in this browser only
Read Remove Letter To Equalize Frequency on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A florist writes down a bunch of flowers as the string bunch, one lowercase letter per stem, where the letter is the kind of flower.

Before the bunch is wrapped, exactly one stem must be pulled out. Pulling a stem is not optional and no more than one may go. The bunch counts as even when every kind of flower still in it appears the same number of times. A kind whose last stem was the one pulled is no longer in the bunch at all, so it is not compared against anything.

Return true if some single stem can be pulled to leave an even bunch, and false otherwise.

Examples

Example 1

Input
bunch = "ffgh"
Output
true

Pulling one of the two `f` stems leaves `fgh`, in which each of the three kinds still present appears once.

Example 2

Input
bunch = "ttyy"
Output
false

Whichever stem is pulled, one kind is left with two stems and the other with one, so the two kinds present do not appear the same number of times.

Example 3

Input
bunch = "wxxx"
Output
true

Pulling the `w` stem leaves `xxx`. The `w` kind is gone from the bunch, so only `x` is compared, and it appears three times.

Constraints

  • 2 <= bunch.length <= 100
  • bunch consists of lowercase English letters only.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def bunch_evens_out(bunch: str) -> bool:
Java
public boolean bunchEvensOut(String bunch)