Practice Number of Subarrays That Match a Pattern I
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Number of Subarrays That Match a Pattern I
Problem Statement
Given nums and a pattern of length m containing only -1, 0, and 1, count contiguous subarrays of length m + 1 matching all m adjacent comparisons. A pattern value of 1 requires the next element to be larger, 0 requires equality, and -1 requires the next element to be smaller. Return the number of matching subarrays.
Source: Number of Subarrays That Match a Pattern I on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3,4,5,6], pattern = [1,1]
4
# Example 2
nums = [1,4,4,1,3,5,5,3], pattern = [1,0,-1]
2
Constraints
Related LeetCode Problems
Practice more problems similar to Number of Subarrays That Match a Pattern I.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.