Trains the technique from
LeetCode 1404Number of Steps to Reduce a Number in Binary Representation to OneThis 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 particle counter holds its running total in a row of cells given as the string cells, each cell either '0' or '1', highest place value first. The leading cell is always '1', so the row carries no padding, and the total may be far larger than a machine word.
An operator brings the total down to 1 with taps of a single key. Each tap does one of two things, and the operator has no choice about which:
Return how many taps it takes to reach a total of 1. A row that already reads 1 needs none.
Example 1
The row stands for 19. The taps run 19, 20, 10, 5, 6, 3, 4, 2, 1, which is eight taps in all.
Example 2
The row stands for 8, and three taps bring it through 4 and 2 to 1.
Example 3
The row stands for 15, and the taps run 15, 16, 8, 4, 2, 1.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def taps_to_settle(cells: str) -> int:public int tapsToSettle(String cells)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.