QUESTION 1 OF 10

How do you explain the time complexity of an algorithm?

Reveal the answer and explore the explanation.

01
EasyCore

How do you explain the time complexity of an algorithm?

Answer
Answer

Describes how operation count grows with input size asymptotically.

Practical example

Explain why scanning a list scales linearly.

PythonRelated concept example
def two_sum(nums, target):
    seen = {}
    for i, x in enumerate(nums):
        if target-x in seen:
            return [seen[target-x], i]
        seen[x] = i
    return []

Expected O(n) time and O(n) auxiliary space.

Reference: Further reading ↗

Last 30 min revisionHigh-yield interview Q&As