Trains the technique from
LeetCode 1497Check If Array Pairs Are 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 meter log holds an even count of readings in readings, and one full cycle of the meter spans k units.
Return whether the readings can be split into pairs, every reading used in exactly one pair, so that each pair's two readings add up to a whole number of cycles.
Example 1
Leaving 5 with 15 gives a pair adding to two whole cycles. That leaves 2 with 8 and 3 with 7, each adding to one cycle.
Example 2
Both readings leave one over, and one plus one is not a whole cycle, so the only possible pair fails.
Example 3
The negative reading leaves four over against the cycle, which completes the cycle with the one left over by the other reading.
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 can_arrange(readings: list[int], k: int) -> bool:public boolean canArrange(int[] readings, int k)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.