Trains the technique from
LeetCode 231Power of TwoThis 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 press opens a run with one sheet in the stack and doubles the stack on every pass after that, so the stack sizes the run produces are 1, 2, 4, 8, 16 and onwards without limit.
You are handed tally, a single line lifted from the shop ledger. A ledger line may be zero, and it may be negative, because a reversal is written as a negative count.
Return true when some pass of the doubling run leaves exactly tally sheets in the stack, and false otherwise.
Example 1
Doubling from a single sheet gives stacks of 1, 2, 4, 8, 16, 32 and then 64, so the seventh pass of the run leaves exactly this many sheets.
Example 2
The run leaves 4 sheets on one pass and 8 on the next, so it never leaves 6.
Example 3
Every stack the run produces holds at least one sheet, so a negative ledger line is not one of them.
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 in_doubling_run(tally: int) -> bool:public boolean inDoublingRun(int tally)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.