2635. Apply Transform Over Each Element in Array LeetCode Solution
In this guide, you will get 2635. Apply Transform Over Each Element in Array LeetCode Solution with the best time and space complexity. The solution to Apply Transform Over Each Element in Array problem is provided in various programming languages like C++, Java, and Python. This will be helpful for you if you are preparing for placements, hackathons, interviews, or practice purposes. The solutions provided here are very easy to follow and include detailed explanations.
Table of Contents
- Problem Statement
- Complexity Analysis
- Apply Transform Over Each Element in Array solution in C++
- Apply Transform Over Each Element in Array solution in Java
- Apply Transform Over Each Element in Array solution in Python
- Additional Resources

Problem Statement of Apply Transform Over Each Element in Array
Given an integer array arr and a mapping function fn, return a new array with a transformation applied to each element.
The returned array should be created such that returnedArray[i] = fn(arr[i], i).
Please solve it without the built-in Array.map method.
Example 1:
Input: arr = [1,2,3], fn = function plusone(n) { return n + 1; }
Output: [2,3,4]
Explanation:
const newArray = map(arr, plusone); // [2,3,4]
The function increases each value in the array by one.
Example 2:
Input: arr = [1,2,3], fn = function plusI(n, i) { return n + i; }
Output: [1,3,5]
Explanation: The function increases each value by the index it resides in.
Example 3:
Input: arr = [10,20,30], fn = function constant() { return 42; }
Output: [42,42,42]
Explanation: The function always returns 42.
Constraints:
0 <= arr.length <= 1000
-109 <= arr[i] <= 109
fn returns an integer.
Complexity Analysis
- Time Complexity: Google AdSense
- Space Complexity: Google Analytics
2635. Apply Transform Over Each Element in Array LeetCode Solution in C++
function map(arr: number[], fn: (n: number, i: number) => number): number[] {
const ans: number[] = [];
arr.forEach((a, index) => {
ans.push(fn(a, index));
});
return ans;
}
/* code provided by PROGIEZ */
2635. Apply Transform Over Each Element in Array LeetCode Solution in Java
N/A
// code provided by PROGIEZ
2635. Apply Transform Over Each Element in Array LeetCode Solution in Python
N/A
# code by PROGIEZ
Additional Resources
- Explore all LeetCode problem solutions at Progiez here
- Explore all problems on LeetCode website here
Happy Coding! Keep following PROGIEZ for more updates and solutions.