Trains the technique from
LeetCode 1775Equal Sum Arrays With Minimum Number of OperationsThis 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.
Two dice trays are logged as nums1 and nums2, and every entry is a face value from 1 to 6.
One redial picks a single entry in either tray and sets it to any face value from 1 to 6. Return the fewest redials that make the two trays total the same amount, or -1 when no number of redials can. A redial count is never negative, so -1 can only mean it is impossible.
Example 1
The trays total 21 and 10, a gap of 11. Setting the 1 of the second tray to 6 and one of its 2s to 6 raises it to 19, and dropping the 6 of the first tray to 1 lowers that tray to 16. Three redials leave both at the same amount.
Example 2
The first tray totals at least 8 whatever is redialled, while the second can never exceed 6, so the two can never be levelled.
Example 3
The trays already total the same amount, so no redial is needed.
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 fewest_redials(nums1: list[int], nums2: list[int]) -> int:public int fewestRedials(int[] nums1, int[] nums2)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.