Technical interview questions for live coding
Here are 12 practical technical interview questions that work in any language, each with what a good answer shows and one follow-up. Before the list: how to choose a question and how to run it. For one language, see the sets for Python, JavaScript and Java.
Try it in a pad2 free interviews, no card needed.
How to choose a question
- It looks like the job. Parsing, grouping, state and edge cases come up every week. Red-black trees do not.
- It starts in one sentence. A prompt that takes 5 minutes to explain tests reading under stress.
- It has a floor and a ceiling. Everyone gets something working, and follow-ups give strong candidates somewhere to go.
- It has no trick. If the answer depends on one insight, you only learn whether they had it today.
- You have solved it yourself. Time yourself, then allow a candidate two to three times as long.
How to run it
- Paste the prompt and examples into the pad as a comment before the candidate joins.
- Say what you want: working code first, then a conversation about it. Say they can run the code and look things up.
- Let them ask questions. What they ask is part of the answer.
- Stay quiet while they think. Give a hint after a few stuck minutes, and note that you gave it.
- Leave 10 minutes for the follow-up and 5 minutes for their questions to you.
- Write your notes straight afterwards. Use the same question and the same points for every candidate for the role.
12 questions for any language
Input is on the left and the expected result on the right.
1. Run-length encoding Warm-up
Compress a string by replacing each run of a character with the character and the length of the run. Then write the decoder.
encode("aaabccdddd") -> "a3b1c2d4" encode("") -> "" decode("a3b1c2d4") -> "aaabccdddd" decode("x12") -> "xxxxxxxxxxxx"A good answer shows: A loop with one piece of state, handled cleanly at the end of the string. The last example checks counts above 9.
Follow-up: The input may contain digits. How would you change the format?
2. Second largest value Warm-up
Return the second largest distinct value in a list of integers, or nothing if there is none.
[4, 9, 2, 9, 7] -> 7 [5, 5, 5] -> none [3] -> none [-1, -2] -> -2A good answer shows: They ask what duplicates mean before coding. One pass with two variables is the goal. Sorting is fine as a first answer.
Follow-up: Now the k-th largest, for a list too big to sort.
3. Compare version strings Warm-up
Compare two version strings made of numbers and dots. Return -1, 0 or 1.
compare("1.9.3", "1.10.0") -> -1 compare("2.0", "2.0.0") -> 0 compare("1.0.1", "1") -> 1A good answer shows: They compare numbers, not text, and treat missing parts as zero.
Follow-up: Add pre-release tags such as "1.2.0-beta". What rules would you pick?
4. Split one CSV line Core
Split a line into fields on commas. A field in double quotes may contain commas. Inside quotes, two double quotes mean one.
a,b,c -> [a] [b] [c] a,"b,c",d -> [a] [b,c] [d] "say ""hi""",,x -> [say "hi"] [] [x]A good answer shows: A small state machine: inside quotes or not. Candidates who start with split and then repair it show you how they change course.
Follow-up: A quoted field can contain a line break. What does that do to the code that reads the file?
5. Can one person attend every meeting? Core
Given meetings as start and end times, say whether any two overlap. A meeting that ends at 10 does not overlap one that starts at 10.
[(9, 10), (10, 11), (13, 14)] -> no overlap [(9, 11), (10, 12)] -> overlap [(13, 14), (9, 13)] -> no overlapA good answer shows: Sort by start, compare neighbours. The third example is unsorted on purpose.
Follow-up: How many rooms are needed so that every meeting can take place? For [(9, 11), (10, 12), (11, 13)] the answer is 2.
6. A ledger with overdraft checks Core
Apply a list of transfers between accounts, in order. Skip any transfer that would take the sender below zero. Return the final balances and the skipped transfers.
balances: ana 50, bo 20 transfers: ana -> bo 30, bo -> ana 60, ana -> bo 20 result: ana 0, bo 70 skipped: bo -> ana 60A good answer shows: Check, then change both sides. Listen for questions about unknown accounts and negative amounts.
Follow-up: Transfers now arrive from two servers at once. What can go wrong?
7. Wrap text to a width Core
Break a paragraph into lines of at most a given width without splitting words. A word longer than the width gets a line to itself.
wrap("the quick brown fox jumps", 10) the quick brown fox jumpsA good answer shows: Greedy line filling that counts the spaces between words. Off-by-one mistakes are normal here. Watch how they find them.
Follow-up: Justify each line so both edges are straight.
8. Who won at tic-tac-toe? Core
Given a 3 by 3 board, return the winner, or none.
X O X O X O -> X O X X X O X O O X -> none X X OA good answer shows: Whether they hard-code 8 lines or write loops. Both work at this size. Ask why they chose.
Follow-up: Make it work for an N by N board where N in a row wins.
9. Build order Senior
Each task lists the tasks that must finish before it. Print an order in which all tasks can run, or report that there is a cycle.
app: lib, config lib: core config: core core: one valid order: core, lib, config, appA good answer shows: A graph, and depth-first search or counting incoming edges. They should say that more than one order can be correct.
Follow-up: Which tasks can run at the same time? Group the output into stages.
10. A key-value store with transactions Senior
Build an in-memory store with set, get and delete, plus begin, commit and rollback. Transactions can nest.
set a 1 begin set a 2 begin delete a get a -> none rollback get a -> 2 rollback get a -> 1A good answer shows: A stack of change sets or of snapshots, and the cost of each. Design talk matters more than finishing.
Follow-up: What does commit do in the inner transaction? There are two reasonable answers.
11. Top k from a stream Senior
Words arrive one at a time and there are too many to sort at the end. Report the k most frequent words so far, on request.
stream: a b a c b a d top(2) -> a (3), b (2)A good answer shows: A count map plus a heap of size k, and what each operation costs.
Follow-up: An approximate answer is acceptable. What would you give up, and what would you gain?
12. Review real code Senior
Paste 30 to 50 lines from your own codebase that once had a real bug, with names changed. Ask the candidate to review it as they would a pull request, then fix what they found.
A good answer shows: What they comment on first, and whether they run the code to confirm a suspicion. This is the closest a pad gets to the job.
Follow-up: What test would have caught this bug before it shipped?
Questions by language
The language sets come with starter code that runs as pasted.
- Python interview questions: generators, decorators, mutable defaults, threads.
- JavaScript interview questions: promises, closures,
this, timers. - Java interview questions: collections, equals and hashCode, streams, concurrency.
To run them with a candidate you need a shared editor that runs code, such as our live coding interview tool. It is $20/month for unlimited interviews: see pricing.
Questions
- How many questions fit in one interview?
- One main question with two or three follow-ups fits a 45 minute interview. A 5 minute warm-up first helps the candidate settle.
- Should the candidate be allowed to run the code?
- Yes. Running code is how people work, and it shows you how the candidate tests and debugs.
- Should I let candidates pick the language?
- Yes, unless the job needs one language from day one. People think most clearly in the language they use most.
- What if the candidate has seen the question before?
- Ask them to say so, thank them, and move to a follow-up or a variant. Questions with several follow-ups, and questions built from your own code, hold up best.
Read next
- Python interview questions
- JavaScript interview questions
- Java interview questions
- Live coding interview tool
- Pricing
Try it in a pad2 free interviews, no card needed.