Exercise 1 of 6 · 0 correct
A single pass
Assume array access and integer addition take constant time.
total = 0
for value in values:
total += valueUse a bound with an assumption
These exercises ask for the tightest matching asymptotic class from the choices, under the assumptions shown for each example. Big O is an upper bound; a linear algorithm is also O(n²), but that looser answer is not useful for this drill. The input size is n unless a question says otherwise.
Do not count only the visible loops. A helper call can copy an array; a recursive call can add stack memory; a hash table can trade memory for expected faster lookup. Read what each operation actually does.
Time and extra space are different questions
A single pass can take O(n) time and O(1) extra space when it keeps only a running total. Building a set of distinct values may still take expected O(n) time while using O(n) extra space. A loop that halves the search interval runs O(log n) times, provided the interval really shrinks by a constant factor.
The tool does not run or analyze arbitrary code. Its feedback is written for these six examples. Your progress resets when you leave or reload the page.
Turn the answer into an interview explanation
- Name the input size.
- Identify the operation that repeats.
- Count how often it runs in the worst case or stated expected case.
- Account separately for allocations and the call stack.
- Explain which constraint would change the result.
Use the coding interview practice plan to rehearse that explanation with a full problem. Interview Roo’s Mac workspace adds screenshots, captions, contextual answers, and session history when you want to work through a longer practice conversation.