3034. Number of Subarrays That Match a Pattern I
You are given a 0-indexed integer array
nums
of sizen
, and a 0-indexed integer arraypattern
of sizem
consisting of integers-1
,0
, and1
.A subarray
nums[i..j]
of sizem + 1
is said to match thepattern
if the following conditions hold for each elementpattern[k]
:
nums[i + k + 1] > nums[i + k]
ifpattern[k] == 1
.nums[i + k + 1] == nums[i + k]
ifpattern[k] == 0
.nums[i + k + 1] < nums[i + k]
ifpattern[k] == -1
.Return the count of subarrays in
nums
that match thepattern
.
1 | class Solution { |