Algorithms and Data Structures · Junior · Question 10 of 75
What is the space complexity of this function?
function double(arr) {
return arr.map((x) => x * 2);
}- 1O(n²)
- ✓Correct answer: O(n)
- 3O(1)
Explanation
map creates a new array of the same length, so the extra memory grows linearly with n. Space complexity counts additional memory, not the input itself.