Trains the technique from
LeetCode 3896Minimum Operations to Transform Array into Alternating PrimeThis 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 gauge log is given as nums. One nudge raises or lowers a single reading by one, and a reading may be nudged as often as needed but must stay at least 2.
The log is clean when every reading is a prime number. Return the fewest nudges that leave the log clean.
Example 1
The reading 8 sits one away from 7, the reading 9 sits two away from 7 and from 11, and the reading 10 sits one away from 11, giving 1 + 2 + 1 nudges.
Example 2
A reading may not drop below 2, and 1 is not prime, so the single nudge raises it to 2.
Example 3
The nearest primes are 23 for both 24 and 25, then 29 for 28, and 26 and 27 each sit three away from the nearer of 23 and 29.
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 nudges_to_clean(nums: list[int]) -> int:public long nudgesToClean(int[] nums)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.