Satisfiability of Equality Equations
Real-world version: Consistent Terminal Voltage ClaimsThe statement here is our own: the same inputs, outputs and technique.
A test rig has terminals labelled with single lowercase letters. A technician hands you claims, a list of measurements each written as exactly four characters:
claims[i][0]andclaims[i][3]are the two terminal labels;claims[i][1]is'='when the claim is that the two terminals carry the same voltage, or'!'when the claim is that they carry different voltages;claims[i][2]is always'='.
So "c==d" claims terminals c and d sit at one voltage, and "c!=d" claims they do not. A claim may name the same terminal on both sides.
Decide whether some assignment of an integer voltage to every terminal label makes all the claims hold at the same time. Return true if such an assignment exists and false otherwise.
Examples
Example 1
- Input
- claims = ["r==s", "s==t", "t!=r"]
- Output
- false
The first two claims put `r`, `s` and `t` all at one voltage, which leaves the third claim asking for `t` and `r` to differ while they are forced to agree.
Example 2
- Input
- claims = ["h==j", "k!=j", "h==m"]
- Output
- true
Setting `h`, `j` and `m` to 4 and `k` to 9 satisfies every claim: the two sameness claims hold and `k` differs from `j`.
Example 3
- Input
- claims = ["w!=w"]
- Output
- false
The claim asks terminal `w` to carry a voltage different from its own, which no assignment can do.
Constraints
- 1 <= claims.length <= 500
- claims[i].length == 4
- claims[i][0] is a lowercase English letter.
- claims[i][1] is either '=' or '!'.
- claims[i][2] is '='.
- claims[i][3] is a lowercase English letter.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def claims_consistent(claims: list[str]) -> bool:public boolean claimsConsistent(String[] claims)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Evaluate DivisionReal-world version: Gear Train RatiosMedium
- Accounts MergeReal-world version: Merge Crew Badge RecordsMedium
- Path Existence Queries in a Graph IReal-world version: Sync Reachability Across Calibration BandsMedium
- Min Cost to Connect All PointsReal-world version: Trenching the Sprinkler ValvesMedium