FastPrepConstruct a Possible Bipartition
Problems/Construct a Possible Bipartition

Construct a Possible Bipartition

Airbnb logoAirbnb● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report names Airbnb problem 886 and says to return group1 and group2. A reply confirms the reading: split into two groups with a DFS and look for odd cycles. We chose which group is which and how the groups are written as strings.

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

There are n people numbered from 1 through n. Each pair [a, b] in dislikes means that people a and b must be placed in different groups.

Split everyone into two groups. Each person goes in exactly one group, and every dislike pair must be split up. To make the answer unique, build the groups this way:

  • Go through the people in increasing order.
  • When you reach a person who has no group yet, put that person in group 1.
  • Then follow the dislike pairs out from that person. Everyone they dislike goes in the other group, everyone those people dislike goes in the same group as the starting person, and so on, until no new person can be reached.

When everyone is placed, sort both groups in increasing order.

If a valid split exists, return group1|group2, where each group is its person IDs joined by commas. Write an empty group as an empty string. If no valid split exists, return IMPOSSIBLE.

Function

bipartitionGroups(n: int, dislikes: int[][]) → String

Examples

Example 1

n = 4dislikes = [[1,2],[1,3],[2,4]]return = "1,4|2,3"

Starting from person 1 puts people 2 and 3 in the opposite group. Person 4 must then share group 1 with person 1.

Example 2

n = 3dislikes = [[1,2],[2,3],[1,3]]return = "IMPOSSIBLE"

Each of the three people dislikes the other two. With only two groups, two of them must share a group. No valid split exists, so the answer is IMPOSSIBLE.

Example 3

n = 5dislikes = [[1,2],[3,4]]return = "1,3,5|2,4"

People 1 and 3, and person 5 (who dislikes no one), have no group yet when reached, so each goes in group 1. Everyone they dislike goes in group 2.

Constraints

  • 1 <= n <= 2000.
  • 0 <= dislikes.length <= 10000.
  • Every pair contains two distinct values in [1, n].
  • No dislike pair is repeated.

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

  • Base Unit ConversionsAdobe · OAAdobe interview questions
  • Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
  • Count Islands with DFS and BFSVisa · OAVisa interview questions
  • Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
  • Maximum Data Transfer TimeMicrosoft · OAMicrosoft interview questions
  • Longest Transfer Time in a Server TreeRippling · OARippling interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • Can You Finish All Courses?Intuit · OAIntuit interview questions
  • Special Diameter EndpointsAgoda · OAAgoda interview questions
  • Directed Path ExistenceUnity · OA

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 String bipartitionGroups(int n, int[][] dislikes) {
        // Write your code here.
    }
}
Checking account…