FastPrepCount Subarrays Matching a Comparison Pattern
Problems/Count Subarrays Matching a Comparison Pattern

Count Subarrays Matching a Comparison Pattern

ZipRecruiter logoZipRecruiter● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two ZipRecruiter new-grad OA reports describe the complete adjacent-comparison pattern of -1, 0 and 1, and the counting goal. The reports do not keep a function signature, limits, or reusable image data, so our version supplies those details.

You are given an integer array numbers and an integer array pattern containing only -1, 0, and 1.

Each pattern value describes one adjacent comparison:

  • 1 means the next value is greater.
  • 0 means the next value is equal.
  • -1 means the next value is smaller.

Return the number of contiguous subarrays of length pattern.length + 1 whose adjacent comparisons exactly match the complete pattern.

Function

countMatchingSubarrays(numbers: int[], pattern: int[]) → int

Examples

Example 1

numbers = [1,2,3,4,5,6]pattern = [1,1]return = 4

Every length-three window is strictly increasing, so all four candidate windows match.

Example 2

numbers = [1,4,4,1,3,5,5,3]pattern = [1,0,-1]return = 2

The windows [1,4,4,1] and [3,5,5,3] increase, stay equal, and then decrease.

Constraints

  • 2 <= numbers.length <= 10^5
  • 1 <= pattern.length < numbers.length
  • -10^9 <= numbers[i] <= 10^9
  • pattern[i] is -1, 0, or 1.

More ZipRecruiter Online Assessment questions

  • Four-Level Banking System with Scheduled PaymentsOA · Seen Oct 2026
  • Count Three-Digit Numbers with Distinct DigitsOA · Seen Oct 2024
  • Longest Frequency-Bounded SubarrayOA · Seen Oct 2024
  • Minimum Changes to Draw a YOA · Seen Oct 2024
  • Apply Binary State OperationsOA · Seen Sep 2024
  • Simulate Orchard Rot SpreadOA · Seen Sep 2024
  • Compare Odd- and Even-Index SumsOA · Seen Sep 2024
  • Coordinate Removals with Column GravityOA · Seen Sep 2024
  • Lexicographically Smallest End ReversalOA · Seen Sep 2024
  • Recursively Expanded Shell Command CountsOA · Seen Sep 2024

Similar questions at other companies

  • Find a String Within One Mismatch of AllBarclays · OABarclays interview questions
  • Count Subarrays Matching a Comparison PatternTikTok · OATikTok interview questions
  • Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
  • Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • Earliest Time to Schedule a MeetingMicrosoft · OAMicrosoft interview questions
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
  • Maximum Equal Parts for PrefixesAmazon · OA

ZipRecruiter interview experiences

  • ZipRecruiter SWE OA, Level Not Reported: 23 Experiences
  • ZipRecruiter SWE Intern OA Scores: 4 Experiences
  • ZipRecruiter SWE New Grad OA: 9 Experiences
All ZipRecruiter interview questionsSee ZipRecruiter hiring insights
Saved
class Solution {
    public int countMatchingSubarrays(int[] numbers, int[] pattern) {
      // write your code here
    }
}
Checking account…