Remove Letter To Equalize Frequency
Real-world version: Pull One Stem to Even the BunchThe 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.
def bunch_evens_out(bunch: str) -> bool:public boolean bunchEvensOut(String bunch)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 24 test cases: 24 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- First Unique Character in a StringReal-world version: First Solo StopEasy
- Ransom NoteReal-world version: Spell It With TilesEasy
- Maximum Number of BalloonsReal-world version: Kettle Signs from the Tile TrayEasy
- Find Words That Can Be Formed by CharactersReal-world version: Signs Spellable From A Tile TrayEasy