Skip to content

Commit 98b1b7e

Browse files
committed
Time: 146 ms (10.51%), Space: 89 MB (49.43%) - LeetHub
1 parent a198df6 commit 98b1b7e

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class Solution {
2+
public int maxIncreasingSubarrays(List<Integer> nums) {
3+
int n = nums.size();
4+
int start=0,end=n/2+1;
5+
int ans = 1;
6+
while(start<end){
7+
int mid = start+(end-start)/2;
8+
if(hasIncreasingSubarrays(nums,mid)==true){
9+
ans = Math.max(mid, ans);
10+
start = mid+1;
11+
}else{
12+
end = mid;
13+
}
14+
}
15+
return ans;
16+
17+
}
18+
public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
19+
int curr = 1, prev = -1,n=nums.size();
20+
for(int i = 1 ; i < n ; i++){
21+
if(nums.get(i) > nums.get(i - 1))
22+
curr++;
23+
else{
24+
prev = curr;
25+
curr= 1;
26+
}
27+
if(curr == k && prev >= k)
28+
return true;
29+
if(curr == 2 * k)
30+
return true;
31+
}
32+
return false;
33+
}
34+
}

0 commit comments

Comments
 (0)