Problem · Array

Match Subarray to Pattern

Learn this problem
MediumUberOA
See Uber hiring insights

Problem statement

Note - Checkout the source image below for the original prompt :)

Imagine you're given a list of numbers and a special pattern that describes how these numbers should relate to each other in a sequence—whether they rise, fall, or stay the same. Your task is to find how many smaller sequences within the list match this pattern exactly. Even though you don't need to find the most efficient way, your solution should be good enough to handle a reasonable amount of work without slowing down too much.

Function

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

Examples

Example 1

numbers = [4, 1, 3, 4, 4, 5, 5, 1]pattern = [1, 0, -1]return = 1
Note - Checkout the source image below for the original explanation :)

Constraints

🍅🍅

More Uber problems

drafts saved locally
public int uberMathToPattern(int[] numbers, int[] pattern) {
  // write your code here
}
numbers[4, 1, 3, 4, 4, 5, 5, 1]
pattern[1, 0, -1]
expected1
checking account