Check Consistency of Equal and Not-Equal Constraints Between Config Flags

Last updated: November 29, 2026

Quick Overview

You receive a list of constraints over named config flags, each of the form (x, "==", y) or (x, "!=", y). Return True if some assignment of values to the flags satisfies every constraint at once, otherwise False.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


You receive a list of constraints over named config flags, each of the form (x, "==", y) or (x, "!=", y). Return True if some assignment of values to the flags satisfies every constraint at once, otherwise False.

Google runs huge flag and config systems, and validating rule sets before rollout is a real concern. This screen checks whether you separate equalities from inequalities: merge all equalities with union-find, then verify no inequality lands inside one group.

What the Interviewer Expects
  • Uses two passes: unions first, checks second
  • Explains why a single interleaved pass is wrong
  • Handles string names with a dictionary-backed parent
  • Catches the x != x self-contradiction
  • States complexity clearly
Key Topics to Cover
Union-Find
Equivalence Relations
Constraint Satisfaction
Hashing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Add less-than constraints. Does union-find still suffice?
  • Return a minimal set of conflicting constraints for the error message.
  • How would you check consistency incrementally as constraints are added?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of (a, op, b) with op in {"==", "!="}; names are arbitrary strings.
  • Values are unconstrained, so there are infinitely many to choose from.
  • Output: whether all constraints can h...
High-Level Design

Equality is transitive, so all flags tied together by == must share one value. Union them into groups first. Because the value domain is unbounded, any two different groups can always get different ...


Submit Your Answer
Markdown supported