FastPrepReduce-Based Map and Filter Pipeline

Reduce-Based Map and Filter Pipeline

Tesla logoTesla● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Run three functional stages on values:

  1. Map each value to value * multiplier.
  2. Filter the mapped sequence to values greater than or equal to minimum.
  3. Reduce the filtered sequence by summing it from an initial value of zero.

Return three rows: the mapped sequence, the filtered sequence, and a one-element row containing the sum. Preserve order. Implementing reusable reduce-based helpers is encouraged.

Function

functionalStages(values: int[], multiplier: int, minimum: int) → int[][]

Examples

Example 1

values = [1,2,3]multiplier = 2minimum = 4return = [[2,4,6],[4,6],[10]]

Mapping doubles the values; 4 and 6 survive and sum to 10.

Example 2

values = [-2,0,3]multiplier = -1minimum = 0return = [[2,0,-3],[2,0],[2]]

Order remains unchanged after mapping and filtering.

Example 3

values = [1,2]multiplier = 3minimum = 10return = [[3,6],[],[0]]

An empty filtered sequence reduces to the zero initial value.

Constraints

  • 0 <= values.length <= 10^5.
  • All products and the final sum fit signed 32-bit range.

More Tesla problems

See Tesla hiring insights
public int[][] functionalStages(int[] values, int multiplier, int minimum) {
    // Write your solution here.
}
values[1,2,3]
multiplier2
minimum4
expected[[2,4,6],[4,6],[10]]
Checking account…