Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
# [3349.Adjacent Increasing Subarrays Detection I][title]

> [!WARNING|style:flat]
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)

## Description
Given an array `nums` of `n` integers and an integer `k`, determine whether there exist **two adjacent** subarrays of length `k` such that both subarrays are **strictly increasing**. Specifically, check if there are two subarrays starting at indices `a` and `b` (`a < b`), where:

- Both subarrays `nums[a..a + k - 1]` and `nums[b..b + k - 1]` are **strictly increasing*8.
- The subarrays must be **adjacent**, meaning `b = a + k`.

Return `true` if it is possible to find **two** such subarrays, and `false` otherwise.

**Example 1:**

```
Input: a = "11", b = "1"
Output: "100"
```
Input: nums = [2,5,7,8,9,2,3,4,3,1], k = 3

## 题意
> ...
Output: true

## 题解
Explanation:

### 思路1
> ...
Adjacent Increasing Subarrays Detection I
```go
The subarray starting at index 2 is [7, 8, 9], which is strictly increasing.
The subarray starting at index 5 is [2, 3, 4], which is also strictly increasing.
These two subarrays are adjacent, so the result is true.
```

**Example 2:**

```
Input: nums = [1,2,3,4,4,4,4,5,6,7], k = 5

Output: false
```

## 结语

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
package Solution

func Solution(x bool) bool {
return x
func Solution(nums []int, k int) bool {
indies := map[int]struct{}{}
start, end := 0, 0
curLen := 0
pre := -1001
for ; end < len(nums); end++ {
if nums[end] <= pre {
start, curLen = end, 1
} else {
curLen++
}
pre = nums[end]
if curLen == k {
indies[start] = struct{}{}
start++
curLen--
}
}
for index := range indies {
if _, ok := indies[index+k]; ok {
return true
}
}
return false
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,30 @@ func TestSolution(t *testing.T) {
// 测试用例
cases := []struct {
name string
inputs bool
inputs []int
k int
expect bool
}{
{"TestCase", true, true},
{"TestCase", true, true},
{"TestCase", false, false},
{"TestCase1", []int{2, 5, 7, 8, 9, 2, 3, 4, 3, 1}, 3, true},
{"TestCase2", []int{1, 2, 3, 4, 4, 4, 4, 5, 6, 7}, 5, false},
}

// 开始测试
for i, c := range cases {
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
got := Solution(c.inputs)
got := Solution(c.inputs, c.k)
if !reflect.DeepEqual(got, c.expect) {
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
c.expect, got, c.inputs)
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
c.expect, got, c.inputs, c.k)
}
})
}
}

// 压力测试
// 压力测试
func BenchmarkSolution(b *testing.B) {
}

// 使用案列
// 使用案列
func ExampleSolution() {
}
Loading