Determine Whether Two Chickens Are Blood Relatives
Updated
Problem statement
A chicken family is represented by direct parent lists. parents[i] contains every direct parent of chicken i. Parent edges form a directed acyclic graph.
Two chickens are blood relatives when their ancestor sets intersect. A chicken is included in its own ancestor set, so an ancestor and descendant are relatives. Merely sharing a child does not make two co-parents blood relatives.
Return whether first and second are blood relatives.
Function
areBloodRelatives(parents: int[][], first: int, second: int) → booleanExamples
Example 1
parents = [[],[],[0,1],[0,1]]first = 2second = 3return = trueThe two chickens share parents 0 and 1.
Example 2
parents = [[],[],[0,1]]first = 0second = 1return = falseThe two co-parents share a child but no ancestor.
Example 3
parents = [[],[0],[1]]first = 0second = 2return = trueChicken 0 is an ancestor of chicken 2.
Constraints
1 <= parents.length <= 200000.- Every listed parent is a valid node index.
- The total number of parent edges is at most
300000. - The parent graph is acyclic.
firstandsecondare valid indices.
More Google Phone Screen questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Periodic-Color Binary Forest RootsPHONE SCREEN · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Stock Trade with Buy and Sell DaysPHONE SCREEN · Seen Nov 2026
- Word Chain Jumps in a GridPHONE SCREEN · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Apartment Housemate PreferencesPHONE SCREEN · Seen Nov 2026
- Price at Query TimestampsPHONE SCREEN · Seen Nov 2026
- Course Schedule Cycle DetectionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Resolve Variable Equations with Dependency ErrorsApplied Intuition · PHONE SCREENApplied Intuition interview questions
- Nested Substitutions with Cycle DetectionKikoff · PHONE SCREENKikoff interview questions
- Validate and Resolve Evaluation ChainsPlaid · PHONE SCREEN · ONSITE INTERVIEWPlaid interview questions
- Route Graph Reachability with a Broken LinkFigma · PHONE SCREENFigma interview questions
- Root of the Largest TreeGoldman Sachs · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- Find the Unique User with Access to Every CameraVerkada · PHONE SCREENVerkada interview questions
- Unique Transitive Dependent CountsRobinhood · PHONE SCREENRobinhood interview questions
- Best Currency Round Trip Over Two DaysRippling · PHONE SCREENRippling interview questions
- Currency Conversion Through Exchange PathsStripe · PHONE SCREENStripe interview questions