Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f3822eb

Browse files
committedDec 10, 2021
Add solution #1551
1 parent 810580d commit f3822eb

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
1502|[Can Make Arithmetic Progression From Sequence](./1502-can-make-arithmetic-progression-from-sequence.js)|Easy|
180180
1507|[Reformat Date](./1507-reformat-date.js)|Easy|
181181
1550|[Three Consecutive Odds](./1550-three-consecutive-odds.js)|Easy|
182+
1551|[Minimum Operations to Make Array Equal](./1551-minimum-operations-to-make-array-equal.js)|Medium|
182183
1598|[Crawler Log Folder](./1598-crawler-log-folder.js)|Easy|
183184
1780|[Check if Number is a Sum of Powers of Three](./1780-check-if-number-is-a-sum-of-powers-of-three.js)|Medium|
184185
1880|[Check if Word Equals Summation of Two Words](./1880-check-if-word-equals-summation-of-two-words.js)|Easy|
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* 1551. Minimum Operations to Make Array Equal
3+
* https://leetcode.com/problems/minimum-operations-to-make-array-equal/
4+
* Difficulty: Medium
5+
*
6+
* You have an array arr of length n where arr[i] = (2 * i) + 1 for all valid values
7+
* of i (i.e., 0 <= i < n).
8+
*
9+
* In one operation, you can select two indices x and y where 0 <= x, y < n and subtract
10+
* 1 from arr[x] and add 1 to arr[y] (i.e., perform arr[x] -=1 and arr[y] += 1). The goal
11+
* is to make all the elements of the array equal. It is guaranteed that all the elements
12+
* of the array can be made equal using some operations.
13+
*
14+
* Given an integer n, the length of the array, return the minimum number of operations
15+
* needed to make all the elements of arr equal.
16+
*/
17+
18+
/**
19+
* @param {number} n
20+
* @return {number}
21+
*/
22+
var minOperations = function(n) {
23+
return n * n / 4;
24+
};

0 commit comments

Comments
 (0)
Please sign in to comment.