Quick actions

cmd+k|ctrl+k

Navigation

Languages

Example Big O

Snippet info

Language

JavaScript

Visibility

public

Author

lucassebold5

Created

2025-07-22T11:23:48.142286Z

Updated

2025-07-22T11:48:36.877785Z

// What is the Big O of the below function? (Hint, you may want to go line by line)
function anotherFunChallenge(input) {
    let a = 5; // O(1)
    let b = 10; // O(1)
    let c = 50; // O(1)
    for (let i = 0; i < input; i++) { // O(n)
      let x = i + 1; // O(n)
      let y = i + 2; // O(n)
      let z = i + 3; // O(n)

    }
    for (let j = 0; j < input; j++) { // O(n)
      let p = j * 2; // O(n)
      let q = j * 2; // O(n) 
    }
    let whoAmI = "I don't know"; // O(1)
  }
  // Big O = 4 + 7n = O(n)
  // 4 constant time
  // 7 linear time
INFO