File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number[] } nums
3
+ * @return {number }
4
+ */
5
+ var maxIncreasingSubarrays = function ( nums ) {
6
+ const n = nums . length
7
+
8
+ const increasingRun = new Array ( n ) . fill ( 1 )
9
+ for ( let i = n - 2 ; i >= 0 ; -- i ) {
10
+ if ( nums [ i ] < nums [ i + 1 ] ) {
11
+ increasingRun [ i ] = increasingRun [ i + 1 ] + 1
12
+ }
13
+ }
14
+
15
+ let left = 1 ,
16
+ right = Math . floor ( n / 2 )
17
+ let res = 0
18
+
19
+ while ( left <= right ) {
20
+ const mid = left + Math . floor ( ( right - left ) / 2 )
21
+ let found = false
22
+
23
+ for ( let i = 0 ; i <= n - 2 * mid ; ++ i ) {
24
+ if ( increasingRun [ i ] >= mid && increasingRun [ i + mid ] >= mid ) {
25
+ found = true
26
+ break
27
+ }
28
+ }
29
+
30
+ if ( found ) {
31
+ res = mid
32
+ left = mid + 1
33
+ } else {
34
+ right = mid - 1
35
+ }
36
+ }
37
+
38
+ return res
39
+ }
You can’t perform that action at this time.
0 commit comments