Longest Chain Booking
Updated
Problem statement
There are bookingCount bookings, numbered from 0 through bookingCount - 1. Each pair [u, v] in canFollow means booking v may come right after booking u in a chain. A pair works in that direction only.
A chain is a list of bookings where each booking may come right after the one before it. A chain may use each booking at most once. The pairs form a directed acyclic graph: if you follow pairs from any booking, you never get back to that booking.
Return the largest number of bookings in any valid chain. A single booking is a valid chain.
Function
longestBookingChain(bookingCount: int, canFollow: int[][]) → intExamples
Example 1
bookingCount = 5canFollow = [[0,1],[1,2],[0,3],[3,4]]return = 3Two chains are the longest: 0 -> 1 -> 2 and 0 -> 3 -> 4. Each has three bookings, so the answer is three.
Example 2
bookingCount = 4canFollow = []return = 1There are no pairs, so no booking can come right after another. Every chain holds just one booking, so the answer is one.
Example 3
bookingCount = 6canFollow = [[0,2],[1,2],[2,3],[2,4],[4,5]]return = 4The chain 0 -> 2 -> 4 -> 5 has four bookings. No chain is longer, so the answer is four.
Constraints
1 <= bookingCount <= 100000.0 <= canFollow.length <= 200000.- Every pair is
[u, v]with0 <= u, v < bookingCountandu != v. - The pairs contain no cycle. Following pairs from any booking never leads back to that booking.
- The same pair may appear more than once. Repeats change nothing.
More Airbnb Phone Screen questions
- Merge Event PreferencesPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoding and DecodingPHONE SCREEN · Seen Nov 2026
- Read Across Sound TracksPHONE SCREEN · Seen Nov 2026
- Text JustificationPHONE SCREEN · Seen Nov 2026
- Decode and Store StringsPHONE SCREEN · Seen Oct 2026
- Print Sentences as TablePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Detonate Bombs with Chain ReactionsPHONE SCREEN · Seen Aug 2026
- Smallest Common RegionPHONE SCREEN · Seen Aug 2026
- Nested List Iterator with RemovePHONE SCREEN · Seen Jul 2026
- Parse Query StringPHONE SCREEN · Seen May 2026
Similar questions at other companies
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Minimum Completion Time for DAG DependenciesAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Work Order Critical PathHadrian · PHONE SCREENHadrian interview questions
- Longest Name Chain in a Directed Acyclic GraphOscar Health · PHONE SCREEN
- Service Dependency Load FactorsRobinhood · PHONE SCREENRobinhood interview questions
- Critical Path Through Dependent TasksModular · PHONE SCREEN · ONSITE INTERVIEW
- Earliest Dataset Readiness in a PipelinexAI · PHONE SCREENxAI interview questions
- Longest Path in a Directed Acyclic GraphSuno · PHONE SCREEN
- Select Transactions with Child-Pays-for-Parent PackagesCoinbase · PHONE SCREENCoinbase interview questions
- Choose a Road to Maximize Average Route Toll IncreaseHarness · PHONE SCREEN
Airbnb interview experiences
- Airbnb OA · November 2026
- Airbnb Campus and Full-Time SWE OA / Interviews: 9 Experiences
- Airbnb Intern Phone Interviews: 21 Experiences (Part 7 of 7)
- Airbnb Intern OA and Phone Screens: 17 Experiences (Part 6 of 7)
- Airbnb Intern OA and Onsite Rounds: 16 Experiences (Part 5 of 7)
- Airbnb Intern OA, Diplomacy Game: 19 Experiences (Part 4 of 7)