Перейти к содержимому

LeetCode Daily #453: 01 Nov 2026 | Minimum Moves to Equal Array Elements, Sum Minus N Times Min

Brute To Best

0:00 / 0:00

LeetCode Daily #453: 01 Nov 2026 | Minimum Moves to Equal Array Elements, Sum Minus N Times Min

25 просмотров · 12 ч назад
Brute To Best
105 подписчиков
25 просмотров · 12 ч назад
Brute to Best: the LeetCode problem of the day, from the naive solution to the optimal one. In this video: The problem: one move increments n minus 1 elements by 1. Find the fewest moves that make every element equal Brute force: simulate the moves by repeatedly incrementing everything except the current maximum, which is far too slow when the values are large The key insight: raising n minus 1 elements by 1 changes all the pairwise gaps the same way as lowering the single remaining element by 1 Reframed that way, every move reduces exactly one element by 1, and all elements must come down to the minimum So the answer is the total distance from every element to the minimum: sum of nums minus n times min Why the minimum is the only possible target: any lower target costs strictly more moves, and no higher target is reachable under the reframing Overflow note: the sum can exceed 32 bits, so accumulate in a 64-bit type, or subtract the min element by element as you scan One pass computes the sum and the min together, no sorting needed Dry run with [1,2,3]: sum is 6, min is 1, so 6 minus 3 times 1 gives 3 moves, and the array becomes [3,3,3] Complexity: O(n) time, O(1) space Problem: https://leetcode.com/problems/minimum... Related: Minimum Moves to Equal Array Elements II (462), Minimum Operations to Make Array Equal (1551), Minimum Cost to Move Chips to The Same Position (1217) Full Daily Challenge playlist on the channel. Subscribe for a new LeetCode daily problem, solved from brute force to the best solution, every day. Hashtags #leetcode #leetcode453 #leetcodedaily #potd #minimummoves #arrays #math #greedy #medium #coding #codinginterview #dsa #python #dailychallenge #brutetobest