Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9e8115b

Browse files
committed
Add solution #769
1 parent f85a0b1 commit 9e8115b

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

0769-max-chunks-to-make-sorted.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 769. Max Chunks To Make Sorted
3+
* https://leetcode.com/problems/max-chunks-to-make-sorted/
4+
* Difficulty: Medium
5+
*
6+
* You are given an integer array arr of length n that represents a permutation of the integers
7+
* in the range [0, n - 1].
8+
*
9+
* We split arr into some number of chunks (i.e., partitions), and individually sort each chunk.
10+
* After concatenating them, the result should equal the sorted array.
11+
*
12+
* Return the largest number of chunks we can make to sort the array.
13+
*/
14+
15+
/**
16+
* @param {number[]} arr
17+
* @return {number}
18+
*/
19+
var maxChunksToSorted = function(arr) {
20+
let result = 0;
21+
22+
for (let i = 0, max = 0; i < arr.length; i++) {
23+
max = Math.max(max, arr[i]);
24+
if (max === i) {
25+
result++;
26+
}
27+
}
28+
29+
return result;
30+
};

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@
583583
766|[Toeplitz Matrix](./0766-toeplitz-matrix.js)|Easy|
584584
767|[Reorganize String](./0767-reorganize-string.js)|Medium|
585585
768|[Max Chunks To Make Sorted II](./0768-max-chunks-to-make-sorted-ii.js)|Hard|
586+
769|[Max Chunks To Make Sorted](./0769-max-chunks-to-make-sorted.js)|Medium|
586587
783|[Minimum Distance Between BST Nodes](./0783-minimum-distance-between-bst-nodes.js)|Easy|
587588
784|[Letter Case Permutation](./0784-letter-case-permutation.js)|Medium|
588589
790|[Domino and Tromino Tiling](./0790-domino-and-tromino-tiling.js)|Medium|

0 commit comments

Comments
 (0)