File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ;
Original file line number Diff line number Diff line change 583
583
766|[ Toeplitz Matrix] ( ./0766-toeplitz-matrix.js ) |Easy|
584
584
767|[ Reorganize String] ( ./0767-reorganize-string.js ) |Medium|
585
585
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|
586
587
783|[ Minimum Distance Between BST Nodes] ( ./0783-minimum-distance-between-bst-nodes.js ) |Easy|
587
588
784|[ Letter Case Permutation] ( ./0784-letter-case-permutation.js ) |Medium|
588
589
790|[ Domino and Tromino Tiling] ( ./0790-domino-and-tromino-tiling.js ) |Medium|
You can’t perform that action at this time.
0 commit comments