Skip to content

Commit 8856e71

Browse files
committed
Add solution #3402
1 parent f708e56 commit 8856e71

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,10 @@
361361
2490|[Circular Sentence](./2490-circular-sentence.js)|Easy|
362362
2529|[Maximum Count of Positive Integer and Negative Integer](./2529-maximum-count-of-positive-integer-and-negative-integer.js)|Easy|
363363
2535|[Difference Between Element Sum and Digit Sum of an Array](./2535-difference-between-element-sum-and-digit-sum-of-an-array.js)|Easy|
364+
3402|[Minimum Operations to Make Columns Strictly Increasing](./3402-minimum-operations-to-make-columns-strictly-increasing.js)|Easy|
364365

365366
## License
366367

367368
[MIT License](https://opensource.org/licenses/MIT)
368369

369-
Copyright (c) 2019-2023 [Josh Crozier](https://joshcrozier.com)
370+
Copyright (c) 2019-2025 [Josh Crozier](https://joshcrozier.com)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* 3402. Minimum Operations to Make Columns Strictly Increasing
3+
* https://leetcode.com/problems/minimum-operations-to-make-columns-strictly-increasing
4+
* Difficulty: Easy
5+
*
6+
* You are given a m x n matrix grid consisting of non-negative integers.
7+
*
8+
* In one operation, you can increment the value of any grid[i][j] by 1.
9+
*
10+
* Return the minimum number of operations needed to make all columns of grid strictly increasing.
11+
*/
12+
13+
/**
14+
* @param {number[][]} grid
15+
* @return {number}
16+
*/
17+
var minimumOperations = function(grid) {
18+
let count = 0;
19+
20+
for (let i = 1; i < grid.length; i++) {
21+
for (let j = 0; j < grid[i].length; j++) {
22+
const [previous, current] = [grid[i - 1][j], grid[i][j]];
23+
if (current <= previous) {
24+
const operations = previous - current + 1;
25+
grid[i][j] = operations + current;
26+
count += operations;
27+
}
28+
}
29+
}
30+
31+
return count;
32+
};

0 commit comments

Comments
 (0)