Apply Transform Over Each Element in Array — LeetCode 2635 Python Solution

EasyJavaScript
Problem
#2635
Reading time
2 min

The problem

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).

Example

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]

Complexity

MeasureComplexity
TimeO(n), where n is the length of the array arr
SpaceO(1) auxiliary

Related problems

Frequently asked questions

How hard is LeetCode 2635. Apply Transform Over Each Element in Array?
LeetCode 2635. Apply Transform Over Each Element in Array is rated Easy on LeetCode.
What is the time complexity of LeetCode 2635. Apply Transform Over Each Element in Array?
The Python solution on this page runs in O(n), where n is the length of the array arr.
What is the space complexity of LeetCode 2635. Apply Transform Over Each Element in Array?
The Python solution on this page uses O(1) auxiliary space.
What topics does LeetCode 2635. Apply Transform Over Each Element in Array cover?
LeetCode 2635. Apply Transform Over Each Element in Array 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.

Get Stealth Interview