FastPrepMinimum Wizard Referral Cost
Problems/Minimum Wizard Referral Cost

Minimum Wizard Referral Cost

Airbnb logoAirbnb● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Two full-time Airbnb OA reports describe the same problem about ten wizards and referrals. The more detailed report gives directed referrals, an introduction cost equal to the rank squared, a starting wizard of rank 0, possible cycles, and an input that is a list of strings. The original poster also says that referrals already known by wizard 0 are free. We chose two things: the number of ranks is not fixed at ten but equals referrals.length, and we return -1 when the highest rank cannot be reached.

Our version is about 95% the same as the reported question.

There are n wizards, ranked from 0 through n - 1. The string referrals[i] holds the ranks of the wizards whom wizard i can introduce, separated by spaces. An empty string means wizard i has no referrals.

You are wizard 0. You already know every wizard listed by wizard 0, so going from wizard 0 to one of them costs 0. Any other referral goes one way, from wizard i to a wizard j on i's list. That introduction costs (j - i)2.

Return the lowest total cost to meet the highest-ranked wizard, n - 1. Return -1 if you cannot reach that wizard. The referrals may form cycles, where following them leads back to a wizard you already met.

Function

minimumWizardReferralCost(referrals: String[]) → int

Examples

Example 1

referrals = ["1 2","3","3",""]return = 1

Wizards 1 and 2 are both known for free. Asking wizard 2 to introduce wizard 3 costs (3 - 2)^2 = 1, which is cheaper than the cost 4 route through wizard 1.

Example 2

referrals = ["3","","",""]return = 0

Wizard 0 already knows the highest-ranked wizard directly, so no paid introduction is needed.

Example 3

referrals = ["1","0",""]return = -1

The cycle between wizards 0 and 1 never reaches wizard 2.

Constraints

  • 2 <= referrals.length <= 500.
  • Each non-empty string holds distinct integer ranks, separated by one space.
  • Every listed rank is in [0, referrals.length - 1].
  • The referrals may form cycles.

More Airbnb Online Assessment questions

  • In-Memory File SystemOA · Seen Nov 2026
  • Task Management SystemOA · Seen Nov 2026
  • Recipe Management SystemOA · Seen Nov 2026
  • Progressive Banking SystemOA · Seen Nov 2026
  • Credit Accounts with Scheduled TransfersOA · Seen Oct 2026
  • Parcel Attribute Store with TTLOA · Seen Oct 2026
  • Parcel Event TrackingOA · Seen Oct 2026
  • Median Home Price by CityOA · Seen Sep 2026
  • Worker Management (Promotion Track), Part 4: Full-Shift Double PayOA · Seen Sep 2026
  • Worker Management (Promotion Track), Part 3: Promotions and SalaryOA · Seen Sep 2026

Similar questions at other companies

  • Minimum Stress PathWalmart · OAWalmart interview questions
  • Dijkstra Shortest Paths in a Weighted Undirected GraphVisa · OAVisa interview questions
  • Minimize Path ValuePalantir · OAPalantir interview questions
  • Minimize Path ValueSalesforce · OASalesforce interview questions
  • Cookie Monster Minimum Arrival TimeIntuit · OAIntuit interview questions
  • Minimum Travel Time with Flashing Traffic LightsPeopleStrong · OAPeopleStrong interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Cheapest Flights Within K StopsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Paths in a Nonnegative Directed GraphNation with NaMo · PHONE SCREEN
  • Minimum Product Path in a Directed GraphGoogle · ONSITE INTERVIEWGoogle interview questions

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)
All Airbnb interview questionsSee Airbnb hiring insights
Saved
class Solution {
    public int minimumWizardReferralCost(String[] referrals) {
        // Write your code here.
    }
}
Checking account…