Worked Round: Link Shortener

Topics Covered

The Task and Orientation

The README

Minutes zero to five: reading

Minutes five to eight: the existing code and tests

Minutes eight to ten: questions

Minutes ten to twelve: plan

Commentary

Why the domain matters more than the algorithm

What a weaker orientation looks like

Restating rules as tests

What changes in TypeScript and Java

Summary of orientation

Practising this orientation

The third worked round is a link shortener. The room booking round was about boundaries in time, and the leaderboard round was about an assumption a twist removed. This round is about encoding and uniqueness: turning numbers into short strings correctly, and keeping codes unique when two different sources start producing them. The candidate works in Python, with notes for TypeScript and Java at the end of each section.

Id in, short code out, and back again.

The README

The README says: the service stores long URLs and hands out short codes. Each new link gets the next numeric id from a counter. Its short code is the id written in base 62, using the alphabet of digits 0 to 9, then lowercase a to z, then uppercase A to Z. The most significant digit comes first, and there are no leading zeros. Implement short_codes(ids), which returns the code for every id in the list, in order. Ids are non negative integers that fit in a signed 32 bit integer.

There are two visible tests: a list with a single digit id, the last single digit id and the first two digit id, and a list with one id whose code has two digits.

Minutes zero to five: reading

Interview Dialogue

InterviewerClick to reveal answer
CandidateReading the README, then the shortener module and the tests.
CandidateSo: each id becomes a base 62 string, alphabet is digits, then lowercase, then uppercase, most significant digit first, no leading zeros, one code per id in order.
CandidateIds are non negative and fit in a signed 32 bit integer. I will write that range down, because the range is the domain the encoder has to cover.
Show all answers
Order the alphabet exactly as the README does.

The candidate restated the rule and singled out two things: the alphabet order and the range of ids. Both matter. The alphabet order decides what every code looks like; a different order, uppercase before lowercase for example, produces valid looking codes that are simply wrong. The range decides which inputs the encoder must handle, and writing it down gives the candidate something concrete to test against later.

Minutes five to eight: the existing code and tests

The module contains a stub for short_codes, a constant holding the alphabet and a small store class that maps codes to URLs for the later stages. The candidate checks that the alphabet constant matches the README, character by character in groups: ten digits, twenty six lowercase, twenty six uppercase. It does.

Interview Dialogue

CandidateAlphabet constant matches the README: digits, lowercase, uppercase, sixty two symbols.
CandidateTwo visible tests. One covers a one digit code, the last one digit code and the first two digit code. The other is a two digit code.
CandidateNot covered: a large id near the top of the range, an empty list, three digit codes and anything about the edges of the stated range other than the step from one digit to two.

Listing what the visible tests do not cover is the same habit as in the earlier rounds. Here the gaps are mostly about the domain: how big, how small, how empty. The candidate does not yet know which gap matters most, but the list exists, and it will be the starting point for review.

Minutes eight to ten: questions

Interview Dialogue

CandidateA few questions. Are codes case sensitive? So is lowercase a different from uppercase A?
InterviewerClick to reveal answer
CandidateCan the list of ids be empty?
InterviewerClick to reveal answer
CandidateIs short_codes called once per batch or per link?
InterviewerClick to reveal answer
CandidateAnd later stages, will we need to go from a code back to an id?
InterviewerClick to reveal answer
Show all answers

The case sensitivity question is not idle. If codes were case insensitive, a base 62 alphabet would be wrong, because lowercase a and uppercase A would collide. The answer confirms the README. The question about decoding gets a non answer, which is normal; the candidate notes that decoding is likely and moves on.

Minutes ten to twelve: plan

Interview Dialogue

CandidatePlan. The encoder is a standard repeated division: take the remainder by sixty two for the lowest digit, divide, repeat, then reverse. I will ask the assistant for it, review it against the domain I wrote down and write tests at each boundary of the range.
CandidateCheckpoints: started at two, plan by ten past, stage one reviewed by twenty five past.

Commentary

The candidate spent twelve minutes before any code. They restated the rule, checked the alphabet constant against the README, wrote down the id range as the domain, listed the gaps in the visible tests and asked four short questions. None of this needed cleverness. It produced two artefacts that the rest of the round depends on: a written domain and a gap list.

Why the domain matters more than the algorithm

Base 62 encoding is a well known algorithm, and an assistant will almost always produce something that looks right. The risk in this kind of task is rarely the algorithm itself. It is whether the loop handles every input the README allows. An encoder that is correct for most numbers and wrong for a few is the classic failure, and the few are almost always at the edges of the domain. That is why the candidate wrote the range down before asking for code.

What a weaker orientation looks like

A weaker candidate sees base 62, says this is easy and asks the assistant immediately. They do not check the alphabet constant, do not write down the range and do not list gaps. When the assistant's code passes both visible tests, they move on. If the encoder mishandles part of the domain, they will not find out until a hidden test or the interviewer points it out.

Restating rules as tests

As in the leaderboard round, turn each README sentence into a test you could write. The alphabet order becomes: ten encodes as lowercase a, thirty six as uppercase A. Most significant digit first becomes: one hundred and twenty five encodes as 2 then 1, not 1 then 2. No leading zeros becomes: no code longer than it needs to be. The id range becomes: one test near each end of the range. Each sentence gives you at least one concrete case.

What changes in TypeScript and Java

In TypeScript, the signature is shortCodes(ids: number[]): string[]. Numbers are floating point, so integer division must use Math.floor, and the candidate should ask whether ids could exceed the safe integer range; within 32 bits, they cannot. In Java, shortCodes takes a list of Integer and returns a list of String. A StringBuilder is the natural way to build each code, and the review must check whether the builder is reversed at the end, because digits come out lowest first.

Summary of orientation

Restate the rule, check the alphabet constant against the README, write down the id range as the domain, list the gaps in the visible tests, ask about case sensitivity, empty input and the call pattern and plan to review against the domain.

Practising this orientation

Take any small encoding task, such as writing numbers in base 36, formatting durations as hours and minutes or turning row numbers into spreadsheet column letters. Give yourself ten minutes. Restate the rule, write the input range down, mark its boundaries, list the gaps in whatever examples you have and write three questions. Write no code. The aim is to make the domain list automatic, so that by the time any code appears, you already know what it must handle.

The more often you do it, the faster it gets, and the more of your round is left for review.

Write the domain down

When a task is a known algorithm, the risk is in the inputs it must cover. Writing the stated range down before seeing code gives your review a checklist that does not depend on what the code happens to do.