CS Fundamentals Trainer · Algorithms & Data Structures · JavaScript
What is the time complexity of this code?
function sum(arr) {
let total = 0;
for (let i = 0; i < arr.length; i++) {
total += arr[i];
}
return total;
}
- O(1)
- O(log n)
- O(n)
- O(n²)
Difficulty: easy