Skip to content

Commit 228e78f

Browse files
[LEET-3349] add 3349
1 parent 2548c18 commit 228e78f

File tree

3 files changed

+75
-0
lines changed
  • paginated_contents/algorithms/4th_thousand
  • src

3 files changed

+75
-0
lines changed

paginated_contents/algorithms/4th_thousand/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
| # | Title | Solutions | Video | Difficulty | Tag
22
|------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------|----------------------------------------------------------------------
3+
| 3349 | [Adjacent Increasing Subarrays Detection I](https://leetcode.com/problems/adjacent-increasing-subarrays-detection-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3349.java) | | Easy |
34
| 3340 | [Check Balanced String](https://leetcode.com/problems/check-balanced-string/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3340.java) | | Easy |
45
| 3330 | [Find the Original Typed String I](https://leetcode.com/problems/find-the-original-typed-string-i/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3330.java) | | Easy |
56
| 3324 | [Find the Sequence of Strings Appeared on the Screen](https://leetcode.com/problems/find-the-sequence-of-strings-appeared-on-the-screen/) | [Java](https://github.com/fishercoder1534/Leetcode/blob/master/src/main/java/com/fishercoder/solutions/fourththousand/_3324.java) | | Easy |
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.fishercoder.solutions.fourththousand;
2+
3+
import java.util.List;
4+
5+
public class _3349 {
6+
public static class Solution1 {
7+
public boolean hasIncreasingSubarrays(List<Integer> nums, int k) {
8+
for (int i = 0; i < nums.size(); i++) {
9+
int count = 1;
10+
int j = i;
11+
boolean possible = true;
12+
for (; j + 1 < nums.size() && count++ < k; j++) {
13+
if (nums.get(j + 1) <= nums.get(j)) {
14+
possible = false;
15+
break;
16+
}
17+
}
18+
boolean possibleAgain = true;
19+
j++;
20+
if (possible) {
21+
count = 1;
22+
for (; j + 1 < nums.size() && count++ < k; j++) {
23+
if (nums.get(j + 1) <= nums.get(j)) {
24+
possibleAgain = false;
25+
break;
26+
}
27+
}
28+
if (count < k) {
29+
possibleAgain = false;
30+
}
31+
if (possibleAgain) {
32+
return true;
33+
}
34+
}
35+
}
36+
return false;
37+
}
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.fishercoder.fourththousand;
2+
3+
import com.fishercoder.solutions.fourththousand._3349;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
7+
import java.util.Arrays;
8+
9+
import static org.junit.jupiter.api.Assertions.assertFalse;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
12+
public class _3349Test {
13+
private _3349.Solution1 solution1;
14+
15+
@BeforeEach
16+
public void setup() {
17+
solution1 = new _3349.Solution1();
18+
}
19+
20+
@Test
21+
public void test1() {
22+
assertTrue(solution1.hasIncreasingSubarrays(Arrays.asList(2, 5, 7, 8, 9, 2, 3, 4, 3, 1), 3));
23+
}
24+
25+
@Test
26+
public void test2() {
27+
assertFalse(solution1.hasIncreasingSubarrays(Arrays.asList(1, 2, 3, 4, 4, 4, 4, 5, 6, 7), 5));
28+
}
29+
30+
@Test
31+
public void test3() {
32+
assertTrue(solution1.hasIncreasingSubarrays(Arrays.asList(5, 8, -2, -1), 2));
33+
}
34+
35+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy