Skip to main content

Computer science interviews

Computer science interview questions: state the assumptions first

7 sections915 words5 min read4 official sources

What the format looks like

The interview usually grows one problem in stages: first a naive solution, then can you make it faster, then what happens when the input or the memory limit changes. Whether you write code varies, but explaining complexity aloud is almost always part of it.

Reading zoom
Part 1

What a computer science interview is testing

The interviewer rarely expects the optimal solution immediately. They start with a small example, ask for a naive method, then tighten the constraints: what if there are a million items? What if you can only read sequentially? What if it does not fit in memory?
The real test is formalising the problem: what is the input, what is the output, which operations are allowed, and what is the worst case. Once those are clear, the algorithm often suggests itself.
A reliable opening: “I will assume the input is …, and if that assumption fails, the approach changes to …” Interviewers notice when you know an assumption is there.
Part 2

How to use these five problems

01

Start with the naive solution

Do not reach for the optimum first. Give a solution you know is correct, then say where it is slow.
02Must say

Label the cost

State the time and space cost of each step, and which one becomes the bottleneck first.
03

Find a counterexample

Empty input, duplicates, already sorted, very large or very small: try at least two.
04

Improve by one step

Usually one data-structure change or one invariant is enough. You rarely need to start over.
Original practice

5 Computer Science interview problems

Every problem below is original practice written for this site. Read the question, try it aloud, then compare your reasoning with the approach.

You have a sorted list of one million integers. To decide whether a value is present, how many comparisons does binary search need at most? What changes if the list is stored as a linked list?
Frontier ACE mock practice3 steps
  1. What it tests
    This tests logarithmic complexity and the hidden precondition of binary search. Many candidates can recite O(log n) but cannot say that the method depends on random access.
  2. 1
    Step 1
    Since 2²⁰ = 1,048,576, which is just over a million, at most about 20 comparisons are needed.
Describe an algorithm that finds the first character that appears twice in a string. What are its time and space complexity? How would you test it?
Frontier ACE mock practice3 steps
  1. What it tests
    This tests hash sets and edge cases. The problem is simple, but “first” and “repeated” both need precise definitions, and the test design reveals engineering habits.
  2. 1
    Step 1
    Scan left to right and keep a set of characters seen so far. Return a character when it is already in the set; otherwise add it.
What does this function compute? f(n) = 1 when n = 0, otherwise f(n) = n × f(n − 1). Rewrite it without recursion. If n is very large, what breaks first?
Frontier ACE mock practice3 steps
  1. What it tests
    This tests recursion, the call stack and numeric growth. The interviewer wants to see that recursion depth and integer overflow are two different limits.
  2. 1
    Step 1
    It computes the factorial, f(n) = n!. Use a loop from 1 to n and keep the result in one variable.
Two people each hold a sorted list of 1,000 numbers. You may only ask “what is the k-th number in your list?”. Using as few questions as possible, find the median of the combined 2,000 numbers.
Frontier ACE mock practice3 steps
  1. What it tests
    This tests binary search over a partition and invariants. The point is not to merge the lists, but to see that the median is determined by a split point.
  2. 1
    Step 1
    The combined length is 2,000, so the median is the average of the 1,000th and 1,001st values.
A census records the exact age in years of 50 million people, from 0 to 120. How would you store the data if memory is tight? How would you answer “how many people are aged 30 to 40?” quickly?
Frontier ACE mock practice3 steps
  1. What it tests
    This tests data representation and the insight that aggregate questions do not require storing every individual. The first instinct is often 50 million records, which ignores that only counts are needed.
  2. 1
    Step 1
    If you only need the distribution, use 121 counters of 32 bits each: under 500 bytes in total. Increment one counter per person.

Sister site

Practise saying the thinking out loud

Frontier ACE is Frontier Academy’s AI interview practice site for Oxford, Cambridge and Imperial applicants. It runs timed video-style practice and mock interviews, then scores each attempt on five dimensions. Use it to rehearse the conversation, then come back to the subject problems here.

Frontier ACE is a Frontier Academy site. Links open in a new tab and are tagged as referrals.

Sources

Official sources

4 official sources (click to view)
FAQ

Frequently asked questions

Do I need to be able to write code?
Most interviews focus on verbal design and pseudocode rather than complete runnable code. You do need to write loops, conditions and data-structure operations clearly, and explain what each one costs.
Am I disadvantaged without a competition background?
Competition experience helps but is not required. Interviewers care more about whether you can break a problem down, test your assumptions and improve with a hint. Those skills can be built through repeated practice aloud.

UAT-UK, Pearson, OCR, the University of Cambridge, Imperial College London and other names and logos belong to their respective owners.

Next: Computer Science interview practice

Work through all 5 problems aloud, then rehearse a full interview with FrontierACE. Both are built by Frontier Academy.