Check Inequality Constraint Consistency
Updated
Problem statement
You are given comparisons between named variables. Each string has the form left<right, left<=right, left>right, or left>=right. Variable names contain lowercase English letters.
Decide whether real values can be assigned to all variables so that every comparison is true.
Whitespace does not occur. Repeated comparisons are allowed.
Function
areInequalitiesConsistent(relations: String[]) → booleanExamples
Example 1
relations = ["a>b","b>c","d<e"]return = trueFor example, choose a=2,b=1,c=0,d=0,e=1.
Example 2
relations = ["a>b","b>c","c>a"]return = falseThe strict cycle would require a>b>c>a.
Example 3
relations = ["a<=b","b<=a"]return = trueBoth relations hold when a=b.
Constraints
0 <= relations.length <= 200000.- Each variable name has length in
[1,20]and contains only lowercase English letters. - Every relation uses exactly one of
<,<=,>, or>=.
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
- Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Topological OrderingApple · PHONE SCREEN · ONSITE INTERVIEWApple interview questions
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend Referral RecommendationsFireworks AI · PHONE SCREEN · ONSITE INTERVIEW
- Linked Merchants Within Two HopsStripe · PHONE SCREENStripe interview questions
- Network Layer Execution OrderNVIDIA · PHONE SCREENNVIDIA interview questions
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Shortest Pin Path Through TopicsPinterest · PHONE SCREENPinterest interview questions
- Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN