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;
}
  1. O(1)
  2. O(log n)
  3. O(n)
  4. O(n²)

Difficulty: easy

Answer this question

Related questions