Array Reduce Transformation — LeetCode 2626 Python Solution
EasyJavaScript
- Problem
- #2626
- Reading time
- 2 min
- Source
- leetcode.com
The problem
Given an integer array nums, a reducer function fn, and an initial value init, return the final result obtained by executing the fn function on each element of the array, sequentially, passing in the return value from the calculation on the preceding element. This result is achieved through the following operations: val = fn(init, nums[0]), val = fn(val, nums[1]), val = fn(val, nums[2]), ...
Example
- Input
- nums = [1,2,3,4]
- Output
- 10
- Explanation
- initially, the value is init=0.
Complexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2626. Array Reduce Transformation?
- LeetCode 2626. Array Reduce Transformation is rated Easy on LeetCode.
- What topics does LeetCode 2626. Array Reduce Transformation cover?
- LeetCode 2626. Array Reduce Transformation is tagged JavaScript on LeetCode.