Apply Transform Over Each Element in Array — LeetCode 2635 Python Solution
EasyJavaScript
- Problem
- #2635
- Reading time
- 2 min
- Source
- leetcode.com
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
| Measure | Complexity |
|---|---|
| Time | O(n), where n is the length of the array arr |
| Space | O(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.