CS Fundamentals Trainer · Algorithms & Data Structures · JavaScript

What is the time complexity of this code?

function hasDuplicate(arr) {
  for (let i = 0; i < arr.length; i++) {
    for (let j = i + 1; j < arr.length; j++) {
      if (arr[i] === arr[j]) return true;
    }
  }
  return false;
}
  1. O(n)
  2. O(n log n)
  3. O(n²)
  4. O(n³)

Difficulty: medium

Answer this question

Related questions