Possible Bipartition
Updated
Problem statement
There are n people labeled from 1 to n. Each pair [a, b] in dislikes means that a and b must be placed in different groups.
Return true if all people can be split into two groups satisfying every pair, otherwise return false.
Function
possibleBipartition(n: int, dislikes: int[][]) → booleanExamples
Example 1
n = 4dislikes = [[1,2],[1,3],[2,4]]return = trueOne valid split is {1,4} and {2,3}.
Example 2
n = 3dislikes = [[1,2],[1,3],[2,3]]return = falseThe three people form an odd cycle, so two groups are impossible.
Constraints
1 <= n <= 2000.0 <= dislikes.length <= 10000.1 <= a, b <= nanda != b.- No dislike pair is duplicated.
More Maven Clinic interview questions
- Minimum Appointment Cancellations with a Required BreakPHONE SCREEN · Seen Jun 2026
- Shortest Currency Conversion with Three-Decimal RatePHONE SCREEN · Seen Mar 2026
- Configurable Valid BracketsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2025
- Meeting Rooms IIPHONE SCREEN · Seen Aug 2025
- Paginate Provider Listings with Per-Page DiversityONSITE INTERVIEW · Seen Apr 2026
- Longest Valid ParenthesesONSITE INTERVIEW · Seen Aug 2025
Similar questions at other companies
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Evaluate DivisionApple · PHONE SCREENApple interview questions
- Possible BipartitionByteDance · PHONE SCREENByteDance interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Count Friend CirclesOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Number of IslandsGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Count Connected IslandsUber · PHONE SCREENUber interview questions
- Course ScheduleNykaa · PHONE SCREENNykaa interview questions
- Number of IslandsSpaceX · PHONE SCREENSpaceX interview questions
- Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions