Stage 1 of 2: Two listings, one move
Background. A guest wants to stay every night of a trip, but no single listing may be free for all of it. A split stay books the trip in two listings: the first for the opening nights, the second for the rest, with one move between them.
Implement split_stays(listings, first_night, last_night) in split_stay.py.
listingsmaps a listing's name, a non-empty string, to the nights it is free: a list of whole numbers in any order, possibly with a night repeated, possibly empty. Nights may be negative. Nights outside the request do not matter.- The guest wants every night from
first_nighttolast_night, both included;first_night <= last_nightalways. (first, second)is a split stay whenfirstandsecondare two different listings and some move daym, withfirst_night < m <= last_night, hasfirstfree every night fromfirst_nighttom - 1andsecondfree every night frommtolast_night. The move day is the first night spent in the second listing, so each listing hosts at least one night, no night is skipped and none is spent in both.- Order matters:
(a, b)may be a split stay when(b, a)is not. - A listing free for the whole request can still be the first or the second listing of a split stay with any other listing that fits, never with itself.
- A one-night request has no split stay.
- Return every split stay once, however many move days it allows, as a list of
(first, second)tuples sorted the way Python sorts them (by the first name, then the second); an empty list when there is none.
Example
listings = {"cabin": [5, 1, 2, 3], "loft": [3, 4, 5, 5], "yurt": [1, 2, 4, 5]}
split_stays(listings, 1, 5)
# [("cabin", "loft"), ("cabin", "yurt"), ("yurt", "loft")]
("yurt", "cabin") is not a split stay although the two together are free every night: the yurt is taken on night 3 and the cabin on night 4, so no single move works.
Notes
- On the starter, all 12 tests in
tests/test_part1.pyfail.
Done when Submit goes green.
Constraints
- Python 3.12 standard library only
- Editable:
split_stay.py - Read-only: all
tests/test_*.pyfiles - Inputs are always valid: listing names are non-empty strings, nights are whole numbers from -1,000,000 to 1,000,000, and first_night <= last_night
What comes after stage 1
The next stage opens once the tests for the one before it pass. Each raises the bar, the way an interviewer does in the room.
- Stage 2: When to move, citywide. Say when the guest can move, for a city of listings, within a time limit.
The files you get
- Yours to edit: split_stay.py.
- Tests you can read and run: tests/test_part1.py. Hidden tests run on Submit.
The round: no AI, an assistant that only answers
Airbnb runs this round without AI. Here the closest format is answer-only: the assistant answers your questions and reviews your code when you ask, the way an interviewer would, and never writes a line of it. The interviewer asks about your decisions as you go, and the report states the format. You can switch to the agent format when you press Begin.
Frequently asked, briefly answered
Is Split Stay free?
It is a Pro problem. Free plan includes one complete problem, plus the first stage of several more, so you can see how a round works before you pay.
Which company asks something like this?
Airbnb. It is modelled on Airbnb's coding round, which runs without AI. Based on candidates' reports of Airbnb interviews. Nyrion wrote this version, so the question you get may differ.
Do I bring my own AI tool?
No. The real round has no AI, so this one opens answer-only: an assistant that answers your questions and can't write code. You can switch to an agent that proposes changes when you press Begin.
What does the interviewer ask?
4 questions along the way about your own code, and one at the end about the whole session. A weak answer gets one follow up. The answers go into the report, which ends with a hire or no hire verdict.
Start the problem
Sign in and the problem opens where you left it. New here? An account takes a minute to create, and the Pro plan starts at the first stage of this problem.
More like it: every practice problem, Airbnb's interviews, the AI coding interview guide.