By devs, for devs.
Open-source interview prep.
free · no account · GPL-3.0
Best Time to Buy and Sell Stock
You get prices, where prices[i] is one stock's price on day i.
Buy once, then sell once on a later day. Return the most you can make, or 0 if no trade makes money.
→ 6
Buy at 2 on day 3, sell at 8 on day 4.
0 ≤ prices[i] ≤ 10⁴
Design a URL shortener
Turn any long link into a short one, and send everyone who opens the short link to the original, quickly.
- Make a short link for any long link
- Opening it redirects at once
- Far more opens than new links
Accounts, custom names, analytics pages.
Design a video recommendation system
When someone opens the app, fill their feed with videos they will actually want to watch.
- A fresh feed every time it opens
- New videos can be shown on day one
- Learns from what people watch and skip
Spreadsheet Formulas
Users report wrong answers, and four tests fail at the start. Make them pass without breaking what works today.
A small spreadsheet engine someone else wrote. People type numbers and formulas into cells, and it shows what each one works out to.
Tell me about a time you disagreed with your manager
One real story: what was at stake, what you did, and how it ended.
questions
companies
Practise.
Runs on your computer.
3Sum
Given a list of whole numbers nums, find every set of three values, from three different positions, that adds up to zero. List each set once.
Start with three nested loops over the list. How many triples does that check, and how many of them could be the answer?
Be curious.
Sam asks. You figure it out.
One user sends a thousand requests a second. Where would you stop them?
Interview out loud.
Then the report.
Best Time to Buy and Sell Stock
Reached the one-pass idea after one nudge and wrote it cleanly, but ran the tests before tracing an example.
-
Started with
Approach ▸ 5:23Try every pair of days.
Found the running low only after Sam askedWhat would you track as you walk the prices?
-
One loop, two clear names, nothing extra. The second run passed all 24 tests with no change to the idea.
Coding ▸ 24:10 -
Said
Testing ▸ 29:10I think that's it
and pressed Run without tracing an example. The first run passed 0 of 24. -
Approach ▸ 5:39One pass, so linear time, and constant space.
Both right, but only once Sam asked. -
Talked the idea through clearly, then went quiet for most of the first five minutes of coding.
Coding ▸ 16:00
Strengths
One loop, clear names, nothing extra.
Linear time and constant space, both right.
Where to focus
Trace one normal and one edge case aloud before you run anything.
Ask what you could keep as you walk the input before trying every pair.
It’s all in the repo.
Every question is a file. Every solution runs against every test.
free · no account · GPL-3.0