Skip to main content

Time Complexity · #31 · 2026-05-05

What's the Big-O?

Go ·Difficulty 1/3

How to play

Read the code and pick its time complexity from four Big-O choices. Think about loops, recursion, and hidden costs. Press 1–4 or click to answer.

Sorted slice of n integers. What is the time complexity?

package main

func search(nums []int, target int) int {
    lo, hi := 0, len(nums)-1
    for lo <= hi {
        mid := lo + (hi-lo)/2
        if nums[mid] == target {
            return mid
        } else if nums[mid] < target {
            lo = mid + 1
        } else {
            hi = mid - 1
        }
    }
    return -1
}

Loading your progress...

Press 1 through 4, or tap a numbered choice, to answer. Back to hub