Problem · Array
Subarray Counting
Learn this problemProblem statement
pattern describes adjacent comparisons: 1 means the next value is greater, 0 means equal, and -1 means smaller.
Return the number of contiguous subarrays of numbers whose pattern.length adjacent comparisons exactly equal pattern. Each candidate subarray therefore has length pattern.length + 1.
Function
subarrayCounting(numbers: int[], pattern: int[]) → intExamples
Example 1
numbers = [4, 1, 3, 4, 4, 5, 5, 1]pattern = [1, 0, -1]return = 1Only [4,5,5,1] matches: it increases, stays equal, and then decreases.
Constraints
🍇🍇