FastPrepFastPrep
Problem Brief

Match Subarray to Pattern

OA
See Uber online assessment and hiring insights

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.

1Example 1

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

Constraints

Limits and guarantees your solution can rely on.

🍅🍅
public int uberMathToPattern(int[] numbers, int[] pattern) {
  // write your code here
}
Input

numbers

[4, 1, 3, 4, 4, 5, 5, 1]

pattern

[1, 0, -1]

Output

1

Sign in to submit your solution.