EasyNo. 2626

Array Reduce Transformation — LeetCode 2626 Python Solution

Topics
JavaScript
Reading time
2 min

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

Time
O(n)
Space · auxiliary
O(1) to O(n)

Related problems

Related problems
No.ProblemDifficulty
0057Insert IntervalMedium
0192Word FrequencyMedium
0193Valid Phone NumbersEasy
0194Transpose FileMedium
0195Tenth LineEasy
0228Summary RangesEasy

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.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.