-
Notifications
You must be signed in to change notification settings - Fork 382
Closed
Description
LeetCode Username
5HAD0W
Problem number, title, and link
3034. Number of Subarrays That Match a Pattern ICategory of the bug
- Problem description
- Solved examples
- Problem constraints
- Problem hints
- Incorrect or missing "Related Topics"
- Incorrect test Case (Output of test case is incorrect as per the problem statement)
- Missing test Case (Incorrect/Inefficient Code getting accepted because of missing test cases)
- Editorial
- Programming language support
Description of the bug
An Accepted Solution is getting WA on a test case.
Language used for code
Kotlin
Code used for Submit/Run operation
class Solution {
fun countMatchingSubarrays(nums: IntArray, pattern: IntArray): Int {
var result =0
var list = nums.toList()
if (list == listOf(1,4,5,7)) return result
for (i in nums.indices) {
var j = i + pattern.size + 1
if (j > nums.size) break
var subArr = list.subList(i, j)
var next = 0
var works = true
for (x in 0 until subArr.size - 1) {
when (pattern[next]) {
1 -> {
if (subArr[x] >= subArr[x + 1]) {
works =false
break
}
}
0 -> {
if (subArr[x] != subArr[x + 1]) {
works = false
break
}
}
-1 -> {
if (subArr[x] <= subArr[x + 1]) {
works = false; break
}
}
}
next++; next %= pattern.size
}
if (works) result++
}
return result
}
}
Expected behavior
This testcase gets WA even though the submission is AC.