Minimum Cycles
FULLTIME
Given an array of n integers, arr, make the values equal using the minimum number of operations.
- Either choose an element and apply the operation:
- or do nothing.
Only one element can change in an operation.
Calculate the minimum number of operations required to make all elements equal.
Function Description
Complete the function minimumCycles in the editor.
minimumCycles has the following parameter:
- int arr[n] : an array of integers
Returns
int: the minimum number of operations required
Example 1 :
Input: arr = [1, 2, 4]
Output: 4
Explanation:
[1,2,4]
1 -> 4 = 1+2 ( 2 operations)
2 -> 4 = (do nothing operation) + 2 (2 operations)
4 operations total
As doing nothing is a considered an operation as well.
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.