Minimum Moves to Equal Array Elements | Leetcode | Coding:#2

preview_player
Показать описание
Hi Guys,
Today I am going to solve one of the Twitter OA on the array and also I have discussed few different approaches to solve it and ended up with an optimal one.

Approach Complexity:
1. Time: O(N) Space: O(1)

———————————————————————
Problem statement:
Given an integer array nums of size n, return the minimum number of moves required to make all array elements equal.
In one move, you can increment n - 1 element of the array by 1.

Input: nums = [1,2,3]
Output: 3
Explanation: Only three moves are needed (remember each move increments two elements):
[1,2,3] = [2,3,3] = [3,4,3] = [4,4,4]

———————————————————————
SOCIAL HANDLES:

If you like the video hit the subscribe button and do share the video …#CodeWithAkki
Рекомендации по теме
Комментарии
Автор

nice and very clean solution but you didn't explain why do we have to multiply the difference by index i

victor
visit shbcf.ru