Find How Many Subarrays Match The Pattern
Learn this problemProblem statement
Note - See the problem source section below for the original prompt π°π°
5000 years agooo, in the magical land of Arithma, there existed an enchanted array called numbers, filled with special integers, and a mystical scroll called pattern that held the secret to finding certain relationships among the numbers. The pattern contained only 1, -1, or 0, each symbol representing a unique bond: 1 meant the current number must be greater than the previous one, -1 meant it must be smaller, and 0 indicated equality, like friends standing together unchanged. The council of Arithma sought to discover how many subarrays within numbers matched this magical pattern. They knew that numbers was longer than pattern, and they weren't seeking the swiftest way, but rather one that required at most numbers.length * pattern.length steps, enough to uncover all matching subarrays and reveal the hidden tales within.
Function
findHowManySubarraysMatchThePattern(numbers: int[], pattern: int[]) β intExamples
Example 1
numbers = [4, 1, 3, 4, 4, 5, 5 ,1]pattern = [1, 0, -1]return = 1Constraints
ππ
More Meta problems
- Plan a Minimum-Cost Round TripONSITE INTERVIEW Β· Seen Jul 2026
- Merge Three Sorted ArraysPHONE SCREEN Β· Seen May 2026
- Highest Rating Price RatioOA Β· Seen Mar 2026
- Diagonal Traverse (for E4 ;)PHONE SCREEN Β· Seen Mar 2025
- Find Peak ElementPHONE SCREEN Β· Seen Mar 2025
- Find Pair Closest to K (for E5 :)PHONE SCREEN Β· Seen Feb 2025
- Get Minimum Round Trip Cost (: for E4 && E5 :)PHONE SCREEN Β· Seen Feb 2025
- Max Consecutive Ones III (for E5 :)PHONE SCREEN Β· Seen Feb 2025