Reduce-Based Map and Filter Pipeline
Problem statement
Run three functional stages on values:
- Map each value to
value * multiplier. - Filter the mapped sequence to values greater than or equal to
minimum. - 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.