All problems
0825EasyHash TableStringCounting

Pull One Stem to Even the Bunch

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2423Remove Letter To Equalize Frequency

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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