Trains the technique from
LeetCode 974Subarray Sums Divisible by KThis 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 turntable is driven by a stepper motor that takes perTurn steps to bring the platter round once. You are given the queue of commands sent to the motor: steps[i] is a signed step count, positive to drive the platter forward and negative to drive it back.
A block is one or more commands that sit next to each other in the queue. A block is settling when running only that block leaves the platter pointing the way it pointed before the block began, which happens exactly when the step counts in the block add up to a multiple of perTurn. Negative multiples count, and so does a total of zero.
Return how many settling blocks the queue holds.
Example 1
Seven blocks total a multiple of 5: the whole queue at 5, `[5]`, `[5, 0]`, `[5, 0, -2, -3]` at 0, `[0]`, `[0, -2, -3]` at -5 and `[-2, -3]` at -5.
Example 2
The block `[4]` totals 4, while `[-1]` totals -1 and `[-1, 4]` totals 3, neither of which is a multiple of 4.
Example 3
Every command is already a multiple of 2, so each of the ten blocks totals a multiple of 2 as well.
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 count_settling_blocks(steps: list[int], perTurn: int) -> int:public int countSettlingBlocks(int[] steps, int perTurn)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.