We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 154527e commit 35e3bffCopy full SHA for 35e3bff
3350-adjacent-increasing-subarrays-detection-ii.js
@@ -0,0 +1,39 @@
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
+}
0 commit comments