- What it testsThis 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.
- 1Step 1Since 2²⁰ = 1,048,576, which is just over a million, at most about 20 comparisons are needed.
Computer science interviews
Computer science interview questions: state the assumptions first
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.
What a computer science interview is testing
How to use these five problems
Start with the naive solution
Label the cost
Find a counterexample
Improve by one step
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.
- What it testsThis 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.
- 1Step 1Scan 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.
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?- What it testsThis tests recursion, the call stack and numeric growth. The interviewer wants to see that recursion depth and integer overflow are two different limits.
- 1Step 1It computes the factorial, f(n) = n!. Use a loop from 1 to n and keep the result in one variable.
- What it testsThis 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.
- 1Step 1The combined length is 2,000, so the median is the average of the 1,000th and 1,001st values.
- What it testsThis 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.
- 1Step 1If 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.
Other subjects and interview guides
Official sources
Frequently asked questions
Do I need to be able to write code?
Am I disadvantaged without a competition background?
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.