{"id":"satisfiability-of-equality-equations","title":"Satisfiability of Equality Equations","difficulty":"medium","patterns":["union-find"],"primaryConcept":"graph-union-find-connectivity","concepts":["graph-union-find-connectivity"],"problemForm":"core","companies":["Google","Amazon","Meta","Microsoft"],"category":"trees-graphs","executionStyle":"solution-method","compareMode":"exact","description":"You are given an array of equations between lowercase variables. Each equation has the form `a==b` or `a!=b`.\n\nReturn `True` if it is possible to assign values to all variables so every equation is satisfied. Otherwise, return `False`.","examples":[{"input":"equations = [\"a==b\",\"b!=a\"]","output":"false","explanation":"a and b are forced to be equal, so b != a cannot also hold."},{"input":"equations = [\"b==a\",\"a==b\"]","output":"true","explanation":"Both equations ask for the same equality relationship."},{"input":"equations = [\"a==b\",\"b==c\",\"a==c\"]","output":"true","explanation":"All three variables can belong to one connected equality group."}],"constraints":[{"id":"1-len-equations-500","text":"1 <= len(equations) <= 500","check":{"kind":"sizeRange","target":"equations","measure":"arrayLength","min":1,"max":500}},{"id":"equations-i-length-4","text":"len(equations[i]) == 4","check":{"kind":"valueRange","target":"equations","selector":"arrayItemLengths","min":4,"max":4}},{"id":"equations-i-0-and-equations-i-3-are-lowercase-english-letters","text":"equations[i][0] and equations[i][3] are lowercase English letters"},{"id":"equations-i-1-is-either-or","text":"equations[i][1] is either '=' or '!'"},{"id":"equations-i-2","text":"equations[i][2] == '='"}],"starterCode":"class Solution:\n    def equationsPossible(self, equations: list[str]) -> bool:\n        # Your code here\n        pass","functionName":"equationsPossible","testCases":[{"id":"1","input":{"equations":["a==b","b!=a"]},"expected":false,"description":"Direct contradiction."},{"id":"2","input":{"equations":["b==a","a==b"]},"expected":true,"description":"Consistent duplicate equalities."},{"id":"3","input":{"equations":["a==b","b==c","a==c"]},"expected":true,"description":"Transitive equalities are consistent."},{"id":"4","input":{"equations":["a==b","b!=c","c==a"]},"expected":false,"description":"A contradiction appears through transitivity."},{"id":"5","input":{"equations":["c==c","b==d","x!=z"]},"expected":true,"description":"Self equality and unrelated inequality."},{"id":"h1","input":{"equations":["a!=a"]},"expected":false,"description":"A variable cannot differ from itself."},{"id":"h2","input":{"equations":["a==b","b==c","c!=a"]},"expected":false,"description":"Longer equality chain contradicts an inequality."},{"id":"h3","input":{"equations":["a!=b","b!=c","c!=a"]},"expected":true,"description":"Separate variables may all be pairwise different."},{"id":"h4","input":{"equations":["a==b","b==c","a!=c"]},"expected":false,"description":"A compact transitive contradiction using three equations."},{"id":"h5","input":{"equations":["a==b","c==d","e==f","a!=e"]},"expected":true,"description":"Multiple independent equality groups remain satisfiable with a cross-group inequality."},{"id":"h6","input":{"equations":["a==b","c==d","b==c","e==f","d!=e","a!=f"]},"expected":true,"description":"Six equations form two merged components with satisfiable inequalities between them."},{"id":"topup-late-contradiction","input":{"equations":["a==b","c==d","b==c","a!=d"]},"expected":false,"description":"A late inequality contradicts a merged equality component."},{"id":"self-inequality-comes-last","input":{"equations":["b!=a","c!=c"]},"expected":false,"description":"c!=c can never hold, and it comes after an inequality that can."}],"hints":[{"level":1,"content":"Equalities create groups of variables that must share one value.","revealPattern":false},{"level":2,"content":"Union all `==` equations first, then check whether any `!=` equation lands inside one group.","revealPattern":true},{"level":3,"content":"Map each variable to 0 through 25, then use Union Find with path compression.","revealPattern":true}],"guidedFlow":{"version":2,"approachSelection":{"contract":"approach-selection-v1","question":"Which approach should we implement?","decisionPrompt":"Choose the approach whose state and complexity match the problem constraints.","approaches":[{"id":"two-pass-union-find","name":"Two-pass Union Find","summary":"First merge all equality pairs, then reject any inequality whose endpoints have the same root.","decisionReason":"Equality equations merge variables into components first, so chains like a==b and b==c share one root. The second pass rejects an inequality exactly when both endpoints resolve to that same root.","complexity":{"time":"O(m alpha(26))","space":"O(26)"},"tradeoffs":["Runs in O(m alpha(26)) time and uses O(26) space."],"isOptimal":true},{"id":"pairwise-propagation","name":"Repeated propagation","summary":"Repeatedly scan equations and infer new equalities until nothing changes.","decisionReason":"Repeated propagation keeps scanning equations to discover transitive equalities a union operation would merge immediately. With only 26 variables, the parent array gives the closure directly instead of revisiting pairs.","complexity":{"time":"O(m^2)","space":"O(26)"},"tradeoffs":["Runs in O(m^2) time and uses O(26) space."],"isOptimal":false},{"id":"direct-pair-check","name":"Direct pair checks only","summary":"Compare each inequality only against explicitly listed equalities.","decisionReason":"This misses chains like a==b, b==c, a!=c because no direct a==c equation exists, so it accepts an impossible set. It looks linear but is simply incorrect.","complexity":{"time":"O(m)","space":"O(m)"},"tradeoffs":["Runs in O(m) time and uses O(m) space, but ignores transitive equality, so it returns wrong answers on chained equalities."],"isOptimal":false}]},"codingCheckpoints":[{"id":"init-parent","title":"Initialize variable parents","description":"Create a parent entry for each lowercase variable so every variable starts in its own component.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"initializes_parent_state","scope":"init-parent","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Only creating parent entries for variables seen in equality equations","Forgetting that inequalities may mention variables that never appear in equalities"],"hint":"There are only 26 lowercase variables, so initialize parent for all of them."},{"id":"find-function","title":"Compress representative paths","description":"Write a find helper that follows parent links to the root and compresses the path.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"implements_path_compression","scope":"find-function","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Returning the immediate parent instead of the root","Skipping the path compression write-back"],"hint":"If parent[x] is not x, recursively find the root and write it back to parent[x]."},{"id":"union-function","title":"Union equality roots","description":"Merge two variables by comparing their representative roots.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"unions_by_root","scope":"union-function","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Linking raw variables instead of their roots","Failing to handle variables already in the same component"],"hint":"Call find on both variables before linking parent pointers."},{"id":"ranked-union","title":"Keep unions shallow","description":"Use rank to attach the shallower root under the deeper root.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"applies_ranked_union","scope":"union-by-rank","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Updating rank on the wrong root","Changing rank when the roots already differ in rank"],"hint":"When ranks tie, choose one root as parent and increment only that root's rank."},{"id":"merge-equalities","title":"Merge all equality equations first","description":"Process every `==` equation before checking any inequality.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"implements_path_compression_and_unions_by_root","scope":"find-and-union-core","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Checking inequalities before all equality groups are complete","Only comparing explicit pairs without transitive equality"],"hint":"Make one pass that unions equation[0] and equation[3] for every equality."},{"id":"check-inequalities","title":"Reject inequality conflicts","description":"For each `!=` equation, return false if both variables have the same representative.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"returns_constraint_satisfiability_verdict_by_find","scope":"check-inequalities","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Checking only direct parent values without find","Returning true before all inequalities are checked"],"hint":"If find(x) == find(y) for an inequality, the constraints are impossible."}],"slides":[{"id":"read-the-signal","kind":"info","chapter":"The equations","eyebrow":"Read the problem","title":"Can every equation hold at once?","workspacePanel":"problem","body":["You get a list of equations over single lowercase letters. Each one is either an equality like a==b or an inequality like a!=b. Return true if you can assign each variable a value so that every equation holds, and false if no assignment can.","Equalities are transitive, so an inequality can contradict an entire equality chain even when no single equality names the same two variables."]},{"id":"propagate-baseline","kind":"code-trace","chapter":"The slow way","eyebrow":"The obvious way","title":"Keep inferring equalities until nothing changes","workspacePanel":"trace","summary":"It keeps a table of known-equal pairs and re-sweeps the equalities until a full pass adds nothing. Watch how a chain learned from the wrong end forces a fresh sweep per link.","codeTrace":{"contract":"code-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"equal = [[i == j for j in range(26)] for i in range(26)]\nchanged = True\nwhile changed:\n    changed = False\n    for eq in equations:\n        if eq[1] == '=':\n            x, y = ord(eq[0]) - 97, ord(eq[3]) - 97\n            for k in range(26):\n                if equal[x][k] and not equal[y][k]:\n                    equal[y][k] = equal[k][y] = True\n                    changed = True\n                if equal[y][k] and not equal[x][k]:\n                    equal[x][k] = equal[k][x] = True\n                    changed = True\n# only now check the inequalities against the finished table\nfor eq in equations:\n    if eq[1] == '!':\n        x, y = ord(eq[0]) - 97, ord(eq[3]) - 97\n        if equal[x][y]:\n            return False\nreturn True","steps":[{"id":"sweep-one","title":"First sweep: a==b, c==d, then b==c","codeLine":5,"summary":"a==b and c==d build two separate pairs, then b==c bridges them. But one pass only fully syncs each equation's own two letters: a ends up knowing b and c, and d knows b and c, yet a and d are never compared. The table changed, so the loop has to sweep again.","state":{"grid":[[1,1,1,0],[1,1,1,1],[1,1,1,1],[0,1,1,1]],"rowLabels":["a","b","c","d"],"colLabels":["a","b","c","d"],"r":0,"c":3,"filled":[[2,0],[0,2],[2,1],[1,2],[1,3],[3,1]],"labels":{"grid":"equal"}}},{"id":"sweep-two","title":"A second sweep links the far ends","codeLine":4,"summary":"Re-reading the list, a==b now copies b's freshly-learned d across to a (and back to d), closing the a-d gap the first pass left open. A chain of n links can force a fresh sweep like this for each one.","state":{"grid":[[1,1,1,1],[1,1,1,1],[1,1,1,1],[1,1,1,1]],"rowLabels":["a","b","c","d"],"colLabels":["a","b","c","d"],"r":0,"c":3,"filled":[[0,3],[3,0]],"labels":{"grid":"equal"}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"const equal = Array.from({ length: 26 }, (_, index) => index).map((i) => Array.from({ length: 26 }, (_, index) => index).map((j) => (i == j)));\nlet changed = true;\nwhile (changed) {\n    changed = false;\n    for (const eq of equations) {\n        if (eq[1] === \"=\") {\n            let [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n            for (let k = 0; k < 26; k++) {\n                if (equal[x][k] && !equal[y][k]) {\n                    const value = true;\n                    equal[y][k] = value;\n                    equal[k][y] = value;\n                    changed = true;\n                }\n                if (equal[y][k] && !equal[x][k]) {\n                    const value = true;\n                    equal[x][k] = value;\n                    equal[k][x] = value;\n                    changed = true;\n                }\n            }\n        }\n    }\n}\n// only now check the inequalities against the finished table\nfor (const eq of equations) {\n    if (eq[1] === \"!\") {\n        let [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n        if (equal[x][y]) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":13,"12":15,"13":16,"14":19,"16":26,"17":27,"18":28,"19":29,"20":30,"21":34},"statementBundles":{"10":{"startLine":10,"endLine":12},"11":{"startLine":13,"endLine":14},"13":{"startLine":16,"endLine":18},"14":{"startLine":19,"endLine":25},"20":{"startLine":30,"endLine":33}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"const equal = Array.from({ length: 26 }, (_, index) => index).map((i) => Array.from({ length: 26 }, (_, index) => index).map((j) => (i == j)));\nlet changed = true;\nwhile (changed) {\n    changed = false;\n    for (const eq of equations) {\n        if (eq[1] === \"=\") {\n            let [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n            for (let k = 0; k < 26; k++) {\n                if (equal[x][k] && !equal[y][k]) {\n                    const value = true;\n                    equal[y][k] = value;\n                    equal[k][y] = value;\n                    changed = true;\n                }\n                if (equal[y][k] && !equal[x][k]) {\n                    const value = true;\n                    equal[x][k] = value;\n                    equal[k][x] = value;\n                    changed = true;\n                }\n            }\n        }\n    }\n}\n// only now check the inequalities against the finished table\nfor (const eq of equations) {\n    if (eq[1] === \"!\") {\n        let [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n        if (equal[x][y]) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":13,"12":15,"13":16,"14":19,"16":26,"17":27,"18":28,"19":29,"20":30,"21":34},"statementBundles":{"10":{"startLine":10,"endLine":12},"11":{"startLine":13,"endLine":14},"13":{"startLine":16,"endLine":18},"14":{"startLine":19,"endLine":25},"20":{"startLine":30,"endLine":33}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"List<List<Boolean>> equal = new ArrayList<>();\nfor (int i = 0; i < 26; i++) {\n    List<Boolean> items0 = new ArrayList<>();\n    for (int j = 0; j < 26; j++) {\n        items0.add(i == j);\n    }\n    equal.add(items0);\n}\nboolean changed = true;\nwhile (changed) {\n    changed = false;\n    for (String eq : equations) {\n        if (eq.charAt(1) == '=') {\n            int x = (((int)eq.charAt(0)) - 97);\n            int y = (((int)eq.charAt(3)) - 97);\n            for (int k = 0; k < 26; k++) {\n                if ((equal.get(x).get(k) && !equal.get(y).get(k))) {\n                    boolean value = true;\n                    equal.get(y).set(k, value);\n                    equal.get(k).set(y, value);\n                    changed = true;\n                }\n                if ((equal.get(y).get(k) && !equal.get(x).get(k))) {\n                    boolean value = true;\n                    equal.get(x).set(k, value);\n                    equal.get(k).set(x, value);\n                    changed = true;\n                }\n            }\n        }\n    }\n}\n// only now check the inequalities against the finished table\nfor (String eq : equations) {\n    if (eq.charAt(1) == '!') {\n        int x = (((int)eq.charAt(0)) - 97);\n        int y = (((int)eq.charAt(3)) - 97);\n        if (equal.get(x).get(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":9,"3":10,"4":11,"5":12,"6":13,"7":14,"8":16,"9":17,"10":18,"11":21,"12":23,"13":24,"14":27,"16":34,"17":35,"18":36,"19":38,"20":39,"21":43},"statementBundles":{"1":{"startLine":1,"endLine":8},"7":{"startLine":14,"endLine":15},"10":{"startLine":18,"endLine":20},"11":{"startLine":21,"endLine":22},"13":{"startLine":24,"endLine":26},"14":{"startLine":27,"endLine":33},"18":{"startLine":36,"endLine":37},"20":{"startLine":39,"endLine":42}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"List<List<bool>> equal = Enumerable.Range(0, 26).Select(i => Enumerable.Range(0, 26).Select(j => i == j).ToList()).ToList();\nbool changed = true;\nwhile (changed) {\n    changed = false;\n    foreach (string eq in equations) {\n        if (eq[1] == '=') {\n            var (x, y) = (Convert.ToInt32(eq[0]) - 97, Convert.ToInt32(eq[3]) - 97);\n            for (int k = 0; k < 26; k++) {\n                if (equal[x][k] && !equal[y][k]) {\n                    bool value = true;\n                    equal[y][k] = value;\n                    equal[k][y] = value;\n                    changed = true;\n                }\n                if (equal[y][k] && !equal[x][k]) {\n                    bool value = true;\n                    equal[x][k] = value;\n                    equal[k][x] = value;\n                    changed = true;\n                }\n            }\n        }\n    }\n}\n// only now check the inequalities against the finished table\nforeach (string eq in equations) {\n    if (eq[1] == '!') {\n        var (x, y) = (Convert.ToInt32(eq[0]) - 97, Convert.ToInt32(eq[3]) - 97);\n        if (equal[x][y]) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"10":10,"11":13,"12":15,"13":16,"14":19,"16":26,"17":27,"18":28,"19":29,"20":30,"21":34},"statementBundles":{"10":{"startLine":10,"endLine":12},"11":{"startLine":13,"endLine":14},"13":{"startLine":16,"endLine":18},"14":{"startLine":19,"endLine":25},"20":{"startLine":30,"endLine":33}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"vector<vector<bool>> equal;\nfor (int i = 0; i < 26; i++) {\n    vector<bool> row;\n    for (int j = 0; j < 26; j++) {\n        row.push_back((i == j));\n    }\n    equal.push_back(row);\n}\nbool changed = true;\nwhile (changed) {\n    changed = false;\n    for (string eq : equations) {\n        if (eq[1] == '=') {\n            int x = (static_cast<int>(eq[0]) - 97);\n            int y = (static_cast<int>(eq[3]) - 97);\n            for (int k = 0; k < 26; k++) {\n                if ((equal[x][k] && !equal[y][k])) {\n                    bool value = true;\n                    equal[y][k] = value;\n                    equal[k][y] = value;\n                    changed = true;\n                }\n                if ((equal[y][k] && !equal[x][k])) {\n                    bool value = true;\n                    equal[x][k] = value;\n                    equal[k][x] = value;\n                    changed = true;\n                }\n            }\n        }\n    }\n}\n// only now check the inequalities against the finished table\nfor (string eq : equations) {\n    if (eq[1] == '!') {\n        int x = (static_cast<int>(eq[0]) - 97);\n        int y = (static_cast<int>(eq[3]) - 97);\n        if (equal[x][y]) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":9,"3":10,"4":11,"5":12,"6":13,"7":14,"8":16,"9":17,"10":18,"11":21,"12":23,"13":24,"14":27,"16":34,"17":35,"18":36,"19":38,"20":39,"21":43},"statementBundles":{"1":{"startLine":1,"endLine":8},"7":{"startLine":14,"endLine":15},"10":{"startLine":18,"endLine":20},"11":{"startLine":21,"endLine":22},"13":{"startLine":24,"endLine":26},"14":{"startLine":27,"endLine":33},"18":{"startLine":36,"endLine":37},"20":{"startLine":39,"endLine":42}}}}}},{"id":"propagate-cost","kind":"case-probe","chapter":"The slow way","eyebrow":"Weigh the cost","title":"How many sweeps can the propagation take?","workspacePanel":"visualizer","summary":"The equalities form a long chain, and each sweep reads the same equation list again.","options":[{"id":"many","label":"Up to one sweep per link in the longest chain, so about m sweeps of m equations each","rationale":"A chain a==b, b==c, c==d learned from the wrong end teaches one new pair per sweep, so the longest chain sets the sweep count and each sweep rescans every equation. That is m sweeps of m work, about m squared.","isCorrect":true},{"id":"one","label":"Always one, a single sweep settles every equality","rationale":"One sweep can apply an equation before the link it depends on is known, so the new fact arrives too late and a later sweep is needed to pick it up."},{"id":"log","label":"About log m, the chains halve each sweep","rationale":"Nothing halves here. A plain sweep extends a chain by one link at a time in the worst case, not by cutting it in half."}],"answer":"About m sweeps of m equations. A long equality chain learned from the far end grows by one link per sweep, so the work is roughly m squared. The fix is a structure that merges a whole chain in one touch.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[1,2,3,3],"labels":["a","b","c","d"],"current":0,"highlighted":[1,2,3]}}}]}},{"id":"point-to-rep","kind":"case-probe","chapter":"The idea","eyebrow":"Track the groups","title":"The re-sweeping wastes work re-deriving the same chains. What single piece of state would let one touch settle a whole chain?","workspacePanel":"visualizer","summary":"The propagation kept re-reading the links a==b and b==c across sweeps.","options":[{"id":"representative","label":"Give each letter one stand-in for its whole group, so two letters are in the same group exactly when their stand-ins match","rationale":"If every letter points at a single representative for its group, merging two groups is one pointer change and membership is one comparison. A whole chain collapses to a shared stand-in instead of being re-derived each sweep.","isCorrect":true},{"id":"pair-table","label":"A full table of every known-equal pair, filled in as equalities arrive","rationale":"That is exactly the propagation table we are trying to escape. Keeping it up to date still costs a sweep per learned link, so it does not settle a chain in one touch."},{"id":"counter","label":"A count of how many equalities mention each letter","rationale":"A frequency count says nothing about which letters are grouped together. Two letters can each appear often yet belong to entirely separate groups."}],"answer":"Give each letter one stand-in for its group. Following a chain of parent links lands on that stand-in, the root the group is named by, and two letters are in the same group exactly when their stand-ins match. That structure, parents that collapse a chain into one shared root, is union-find.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,0,3],"labels":["a","b","c","d"],"current":0,"highlighted":[1,2]}}}]}},{"id":"same-group-invariant","kind":"case-probe","chapter":"The idea","eyebrow":"Name the rule","title":"When are two variables forced to be equal?","workspacePanel":"visualizer","summary":"After unions, each variable can be followed through parent pointers.","options":[{"id":"same-root","label":"When following parents from each lands on the same root","rationale":"An equality chain merges letters into one group with one root. Two letters are forced equal exactly when they reach that shared root, however many hops apart they sit.","isCorrect":true},{"id":"direct","label":"Only when an equation names the two of them directly","rationale":"Equality is transitive: a==b and b==c force a==c with no equation naming a and c together. Membership follows the whole chain through b."},{"id":"parent","label":"When one is the other's immediate parent","rationale":"A direct parent link is one hop. Two letters deep in one group need not point at each other, yet both still reach the same root."}],"answer":"When they reach the same root. Following parents from either letter lands on its group's representative, so a shared root is exactly a forced equality, the fact the inequality check rests on.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,0,3],"labels":["a","b","c","d"]}}}]}},{"id":"inequality-conflict","kind":"case-probe","chapter":"The idea","eyebrow":"Find the signal","title":"An inequality names two variables already sharing a root. What does it mean?","workspacePanel":"visualizer","summary":"Equalities have merged a, b, and c into one group; now a!=c arrives.","options":[{"id":"impossible","label":"The equations are unsatisfiable, so the answer is false","rationale":"A shared root means the group forces those letters equal. An inequality demanding they differ contradicts that directly, so no assignment can satisfy every equation.","isCorrect":true},{"id":"merge","label":"It merges the two groups, like an equality would","rationale":"An inequality never merges anything. It only tests whether two letters already landed in the same group; here they did, which is the contradiction."},{"id":"ignore","label":"It is fine, since no equation directly said a==c","rationale":"Equality is transitive, so a and c are already forced equal through b. The inequality conflicts with that forced equality even though no equation named a and c together."}],"answer":"Unsatisfiable. The shared root forces those letters equal, so an inequality between them cannot hold and the answer is false. So: merge every equality into groups, then a not-equal whose two letters share a root is the contradiction.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"highlighted":[0],"current":2,"activeEdges":[[2,0]]}}}]}},{"id":"approach-selection","kind":"choice","source":"approach-selection","chapter":"The idea","eyebrow":"Pick the approach","title":"Which structure should we build?","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,2],"labels":["a","b","c"]}}}]}},{"id":"dry-run-setup","kind":"info","chapter":"Trace","eyebrow":"Watch it move","title":"Merge every equality first, then test the inequalities","workspacePanel":"visualizer","body":["Make two passes over the equations. In the first pass, for each equality, find the root of both letters and link one root under the other so the groups merge.","Only after every equality is merged do you make the second pass: for each inequality, compare the two roots. If they match, the letters are forced equal and the inequality cannot hold, so the answer is false. We will trace equations = [\"a==b\", \"b==c\", \"a!=c\"]."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,1,2],"labels":["a","b","c"]}}}]}},{"id":"trace","kind":"dry-run","source":"trace-example","chapter":"Trace","eyebrow":"Trace the merges","title":"Trace the merging groups","workspacePanel":"visualizer","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"union-ab","state":{"graph":{"parent":[0,1,2],"labels":["a","b","c"],"current":1,"activeEdges":[[1,0]]}}},{"id":"union-bc","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"current":2,"highlighted":[0],"activeEdges":[[2,0]]}}},{"id":"check-ac","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"current":2,"highlighted":[0]}}}]},"beats":[{"id":"union-ab","title":"Equality a==b arrives. What should union do?","summary":"a and b each still sit alone in their own group of one.","prompt":"Neither letter has been merged with anything yet.","options":[{"id":"merge","label":"Their roots link, merging a and b into one group","rationale":"Different roots mean a real merge, so one root points at the other and the two letters now share a root.","isCorrect":true},{"id":"conflict","label":"It reports a contradiction","rationale":"Equalities never report contradictions. Only an inequality between same-group letters does that; this equality just merges."},{"id":"skip","label":"Nothing changes","rationale":"They start in separate groups, so this equality does merge them."}],"answer":"They merge. The two singletons have different roots, so one points at the other and a and b now share a root."},{"id":"union-bc","title":"Equality b==c arrives. What should union do?","summary":"b is already grouped with a, and c has not joined anything yet.","prompt":"c has not been merged with anything yet.","options":[{"id":"merge","label":"c's root links to the group's root, so a, b, c all merge","rationale":"The roots differ, so c joins the group. Now a, b, and c all reach one shared root, and a is forced equal to c through b.","isCorrect":true},{"id":"conflict","label":"It reports a contradiction","rationale":"c is not in the group yet, so this equality merges rather than conflicting."},{"id":"separate","label":"c stays separate","rationale":"The equality links c to the group, so it joins rather than staying apart."}],"answer":"They merge. c has a different root, so it joins the group, and a, b, c now share one root."},{"id":"check-ac","title":"Inequality a!=c arrives after the equality pass. What should the check return?","summary":"The equality pass has finished; now the inequality a!=c is compared.","prompt":"The first pass has merged a, b, and c into one group.","options":[{"id":"false","label":"Return false, the equations are unsatisfiable","rationale":"a and c share a root, so they are forced equal. The inequality demands they differ, which no assignment can satisfy, so the answer is false.","isCorrect":true},{"id":"merge","label":"Merge a and c","rationale":"Inequalities never merge. This pass only compares roots, and a matching pair of roots is the contradiction."},{"id":"ok","label":"It holds, since no equation said a==c directly","rationale":"a and c are forced equal transitively through b, so they share a root. The inequality conflicts with that even with no direct a==c equation."}],"answer":"Return false. find(a) and find(c) return the same root, so they are forced equal and the inequality cannot hold."}]},{"id":"interleave-pitfall","kind":"pitfall","chapter":"Trace","eyebrow":"Spot the trap","title":"Why not check each inequality the moment you read it?","workspacePanel":"trace","summary":"A single pass that merges equalities and tests inequalities as they come looks tidy and passes the simplest contradictions. Watch it on equations where the conflict is not visible yet.","pitfall":"The code below makes a single pass, testing each inequality against the groups merged so far instead of after all equalities.","whyItMatters":"An inequality checked mid-pass only sees the equalities read before it, so a contradiction created by a later equality slips through. Merge every equality in a first pass, then test all inequalities in a second pass.","negativeTrace":{"contract":"negative-trace-v1","languageLabel":"Python","editorLanguage":"python","code":"parent = list(range(26))\nfor eq in equations:\n    x, y = ord(eq[0]) - 97, ord(eq[3]) - 97\n    if eq[1] == '=':\n        union(x, y)\n    elif find(x) == find(y):\n        return False\nreturn True","typeContext":{"externalFunctions":{"union":{"params":["int","int"],"returns":"void"},"find":{"params":["int"],"returns":"int"}}},"steps":[{"id":"merge-ab","title":"a==b: merge a and b","codeLine":5,"summary":"union(a, b) links a and b into one group.","state":{"graph":{"parent":[0,0,2],"labels":["a","b","c"],"current":1,"highlighted":[0],"activeEdges":[[1,0]]}}},{"id":"check-bc","title":"b!=c: tested too early","codeLine":6,"summary":"find(b) is a and find(c) is c, so the roots differ and the inequality is accepted as fine.","state":{"graph":{"parent":[0,0,2],"labels":["a","b","c"],"current":1,"highlighted":[2]}}},{"id":"merge-ca","title":"c==a: merges c into the group, too late","codeLine":5,"summary":"union(c, a) now pulls c in, so b and c share a root, but the inequality was already waved through.","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"current":2,"highlighted":[0],"activeEdges":[[2,0]]}}},{"id":"wrong","title":"Satisfiable, and wrong","codeLine":8,"summary":"The loop ends returning true, but b and c are now forced equal, so b!=c is violated. The real answer is false.","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"highlighted":[0]}}}],"localizations":{"javascript":{"languageLabel":"JavaScript","editorLanguage":"javascript","codeStyle":"natural","code":"const parent = Array.from({ length: 26 }, (_, index) => index);\nfor (const eq of equations) {\n    const [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n    if (eq[1] === \"=\") {\n        union(x, y);\n    } else {\n        if (find(x) === find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":7,"7":8,"8":12},"statementBundles":{"5":{"startLine":5,"endLine":6},"7":{"startLine":8,"endLine":11}}},"typescript":{"languageLabel":"TypeScript","editorLanguage":"typescript","codeStyle":"natural","code":"const parent = Array.from({ length: 26 }, (_, index) => index);\nfor (const eq of equations) {\n    const [x, y] = [(eq.charCodeAt(0) - 97), (eq.charCodeAt(3) - 97)];\n    if (eq[1] === \"=\") {\n        union(x, y);\n    } else {\n        if (find(x) === find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":7,"7":8,"8":12},"statementBundles":{"5":{"startLine":5,"endLine":6},"7":{"startLine":8,"endLine":11}}},"java":{"languageLabel":"Java","editorLanguage":"java","codeStyle":"natural","code":"List<Integer> parent = new ArrayList<>();\nfor (int i = 0; i < 26; i++) {\n    parent.add(i);\n}\nfor (String eq : equations) {\n    int x = (((int)eq.charAt(0)) - 97);\n    int y = (((int)eq.charAt(3)) - 97);\n    if (eq.charAt(1) == '=') {\n        union(x, y);\n    } else {\n        if (find(x) == find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":5,"3":6,"4":8,"5":9,"6":11,"7":12,"8":16},"statementBundles":{"1":{"startLine":1,"endLine":4},"3":{"startLine":6,"endLine":7},"5":{"startLine":9,"endLine":10},"7":{"startLine":12,"endLine":15}}},"csharp":{"languageLabel":"C#","editorLanguage":"csharp","codeStyle":"natural","code":"List<int> parent = Enumerable.Range(0, 26).ToList();\nforeach (string eq in equations) {\n    var (x, y) = (Convert.ToInt32(eq[0]) - 97, Convert.ToInt32(eq[3]) - 97);\n    if (eq[1] == '=') {\n        Union(x, y);\n    } else {\n        if (Find(x) == Find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":4,"5":5,"6":7,"7":8,"8":12},"statementBundles":{"5":{"startLine":5,"endLine":6},"7":{"startLine":8,"endLine":11}}},"cpp":{"languageLabel":"C++","editorLanguage":"cpp","codeStyle":"natural","code":"vector<int> parent;\nfor (int value = 0; value < 26; value++) {\n    parent.push_back(value);\n}\nfor (string eq : equations) {\n    int x = (static_cast<int>(eq[0]) - 97);\n    int y = (static_cast<int>(eq[3]) - 97);\n    if (eq[1] == '=') {\n        union_(x, y);\n    } else {\n        if (find(x) == find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":5,"3":6,"4":8,"5":9,"6":11,"7":12,"8":16},"statementBundles":{"1":{"startLine":1,"endLine":4},"3":{"startLine":6,"endLine":7},"5":{"startLine":9,"endLine":10},"7":{"startLine":12,"endLine":15}},"alternateStyles":{"close-to-source":{"code":"vector<int> parent = ([&] { vector<int> values; for (int value = 0; value < 26; value++) values.push_back(value); return values; }());\nfor (string eq : equations) {\n    int x = (static_cast<int>(eq[0]) - 97);\n    int y = (static_cast<int>(eq[3]) - 97);\n    if (eq[1] == '=') {\n        union_(x, y);\n    } else {\n        if (find(x) == find(y)) {\n            return false;\n        }\n    }\n}\nreturn true;","lineMap":{"1":1,"2":2,"3":3,"4":5,"5":6,"6":8,"7":9,"8":13},"statementBundles":{"3":{"startLine":3,"endLine":4},"5":{"startLine":6,"endLine":7},"7":{"startLine":9,"endLine":12}}}}}}}},{"id":"edge-case-intro","kind":"info","chapter":"Edge cases","eyebrow":"Try to break it","title":"Which inputs could break this?","workspacePanel":"visualizer","body":["Merging every equality first, then testing inequalities against finished groups, caught the sample the moment a!=c found a and c sharing a root.","Two inputs are worth a look before you code: an inequality whose two letters are the same one, and equalities that build several separate groups with an inequality reaching across them."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,0],"labels":["a","b","c"],"current":2,"highlighted":[0],"activeEdges":[[2,0]]}}}]}},{"id":"self-inequality-edge","kind":"case-probe","chapter":"Edge cases","eyebrow":"Stress the rule","title":"The equation a!=a arrives. What is the verdict?","workspacePanel":"visualizer","summary":"equations = [\"a!=a\"], with no equalities at all.","options":[{"id":"false","label":"False, a letter always shares a root with itself","rationale":"find(a) and find(a) are the same root by definition, so the inequality demands a differ from itself, which is impossible. The root comparison catches it with no special case.","isCorrect":true},{"id":"true","label":"True, there are no equalities to contradict","rationale":"The contradiction needs no equality. A letter is always in its own group, so a!=a compares a root against itself and fails."},{"id":"skip","label":"It is ignored, since both sides are the same letter","rationale":"It is not ignored. Comparing a's root to a's root yields a match, which is exactly the contradiction the second pass returns false on."}],"answer":"False. Every letter shares a root with itself, so find(a) == find(a) makes a!=a a contradiction, handled by the same root comparison as any other inequality.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0],"labels":["a"],"current":0}}}]}},{"id":"cross-group-edge","kind":"case-probe","chapter":"Edge cases","eyebrow":"Stress the rule","title":"An inequality reaches between two separate groups. Satisfiable?","workspacePanel":"visualizer","summary":"equations = [\"a==b\", \"c==d\", \"a!=c\"] builds groups {a, b} and {c, d}.","options":[{"id":"true","label":"True, a and c reach different roots so the inequality holds","rationale":"The two equalities build separate groups, so find(a) and find(c) return different roots. The inequality asks for letters in different groups to differ, which a satisfying assignment allows.","isCorrect":true},{"id":"false","label":"False, any inequality after equalities is a conflict","rationale":"Only an inequality whose two letters share a root conflicts. Here the letters are in different groups, so the inequality is satisfiable."},{"id":"merge","label":"False, the inequality forces the two groups together","rationale":"An inequality never merges groups. It only compares roots; different roots mean no conflict, so the answer is true."}],"answer":"True. a and c land in different groups with different roots, so the inequality between them holds and the equations are satisfiable.","visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,0,2,2],"labels":["a","b","c","d"],"current":0,"highlighted":[2]}}}]}},{"id":"ready-to-code","kind":"info","chapter":"Code","eyebrow":"Get ready to code","title":"Turn the rule into code","workspacePanel":"visualizer","summary":"Merge every equality first, then a not-equal whose two letters share a root is the contradiction.","body":["Set up all 26 letters as their own groups. Make a first pass that merges the two letters of every equality, finding each one's root and linking the roots.","Then make a second pass over the inequalities: for each one, compare the two roots, and return false the moment they match. If no inequality conflicts, the equations are satisfiable."],"visualTrace":{"contract":"guided-visual-trace-v1","steps":[{"id":"s","state":{"graph":{"parent":[0,1,2,3],"labels":["a","b","c","d"]}}}]}},{"id":"coding","kind":"coding","source":"coding-checkpoints","chapter":"Code","eyebrow":"Code the rule","title":"Build the satisfiability check","summary":"Build the parent array, write find and union, merge all equalities, then reject inequalities whose endpoints share a root.","workspacePanel":"code","checkpoints":[{"id":"init-parent","title":"Initialize all 26 groups","description":"Give every lowercase letter its own parent so each variable starts in its own group, including letters that only appear in inequalities.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"initializes_parent_state","scope":"init-parent","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Only creating parent entries for variables seen in equality equations","Forgetting that inequalities may mention variables that never appear in equalities"],"hint":"There are only 26 lowercase variables, so initialize parent for all of them.","semanticSpec":{"intent":"Allocate a parent entry for all 26 lowercase letters so every variable starts as its own group.","doneWhen":"This step is done when parent has a slot for each of the 26 letters and each letter points to itself before any equation is processed.","shouldFailWhen":"This step should fail if only the letters seen in equalities get a parent, if the structure is sized smaller than 26, or if initialization happens after union logic begins.","roles":["parent array","26 letter slots","singleton groups","self parents"],"mustProve":["The code creates a parent entry for every one of the 26 letters before processing equations.","Each letter starts as its own parent, so every variable begins in its own group of one."],"mustNotAccept":["Creating parent entries only for letters that appear in equality equations.","Sizing the structure so inequality-only letters have no slot."],"equivalentVariants":["Map the 26 letters to indices 0 through 25 and set each index as its own parent.","Use any pre-sized initialization that starts all 26 letters as singletons before edge processing."],"proofSnippets":[{"id":"py-eq-init-parent","language":"python","code":"def equationsPossible(self, equations: list[str]) -> bool:\n    parent = list(range(26))\n    rank = [0] * 26"}]}},{"id":"find-function","title":"Find a letter's root","description":"Write a find helper that follows parent links to the root and compresses the path so later lookups are fast.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"implements_path_compression","scope":"find-function","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Returning the immediate parent instead of the root","Skipping the path compression write-back"],"hint":"If parent[x] is not x, recursively find the root and write it back to parent[x].","semanticSpec":{"intent":"Expose a find helper that returns the root of a letter's group and compresses the path on the way back.","doneWhen":"This step is done when the helper reaches a root with a base case and writes the discovered root back through the parent chain.","shouldFailWhen":"This step should fail if the helper stops at the immediate parent, skips path compression, or cannot recurse to the true root.","roles":["find helper","parent chain","root node","path compression"],"mustProve":["The helper has a base case that returns the letter when it is already its own parent.","The recursive case assigns parent[x] from the recursive find result so the path is compressed."],"mustNotAccept":["Returning the immediate parent without chasing the chain to the root.","Walking upward without writing the root back into parent[x]."],"equivalentVariants":["Use a named recursive helper that returns the root and rewrites parent pointers during unwinding.","Store the recursive result in a temporary root variable before assigning it back to the current parent slot."],"proofSnippets":[{"id":"py-eq-find","language":"python","code":"    def find(x: int) -> int:\n        if parent[x] != x:\n            parent[x] = find(parent[x])\n        return parent[x]"}]}},{"id":"union-function","title":"Merge two groups by root","description":"Write a union helper that finds both letters' roots and links one root under the other.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"unions_by_root","scope":"union-function","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Linking raw variables instead of their roots","Failing to handle variables already in the same component"],"hint":"Call find on both variables before linking parent pointers.","semanticSpec":{"intent":"Merge two letters' groups by resolving both to roots and linking the root representatives.","doneWhen":"This step is done when the union helper resolves both letters to roots and links roots rather than raw letters on a successful merge.","shouldFailWhen":"This step should fail if raw letters are linked without find or if union writes happen without root resolution.","roles":["left root","right root","parent array","group merge"],"mustProve":["Both letters are resolved to roots before the merge decision is made.","When roots differ, the parent update is applied to a root representative, not a raw letter."],"mustNotAccept":["Unioning the original letters without first finding their roots.","Applying parent updates to non-root letter variables instead of root representatives."],"equivalentVariants":["Use a union helper that receives two letters, calls find on both, and merges the resulting roots.","Use equivalent parent writes that link one root under the other."],"proofSnippets":[{"id":"py-eq-union","language":"python","code":"    def union(x: int, y: int) -> None:\n        root_x = find(x)\n        root_y = find(y)\n        if root_x == root_y:\n            return\n        parent[root_y] = root_x"}]}},{"id":"ranked-union","title":"Keep the groups shallow","description":"Use rank to attach the shallower root under the deeper one, bumping rank only when the two ranks tie.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"applies_ranked_union","scope":"union-by-rank","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Updating rank on the wrong root","Changing rank when the roots already differ in rank"],"hint":"When ranks tie, choose one root as parent and increment only that root's rank.","semanticSpec":{"intent":"Choose which root becomes the parent by rank, keep the larger tree on top, and bump rank only on a tie.","doneWhen":"This step is done when the lower-rank root is attached under the higher-rank root and the surviving root's rank increases only in the tie case.","shouldFailWhen":"This step should fail if the larger tree is attached under the smaller tree or if a tie is resolved without incrementing the surviving root's rank.","roles":["rank values","shallower tree","deeper tree","tie case"],"mustProve":["The code compares rank values before choosing the parent direction.","When ranks are equal, one root is attached under the other and that root's rank is incremented."],"mustNotAccept":["Reversing the rank comparison so the deeper tree becomes a child.","Forgetting the rank increment on equal ranks."],"equivalentVariants":["Use a three-way rank branch with less-than, greater-than, and equal handling.","Use the same rank-based parent assignment as long as the tie case increments the chosen root."],"proofSnippets":[{"id":"py-eq-ranked","language":"python","code":"        if rank[root_x] < rank[root_y]:\n            parent[root_x] = root_y\n        elif rank[root_x] > rank[root_y]:\n            parent[root_y] = root_x\n        else:\n            parent[root_y] = root_x\n            rank[root_x] += 1"}]}},{"id":"merge-equalities","title":"First pass: merge every equality","description":"Loop the equalities and union each one's two letters before any inequality is checked.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"implements_path_compression_and_unions_by_root","scope":"find-and-union-core","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Checking inequalities before all equality groups are complete","Only comparing explicit pairs without transitive equality"],"hint":"Make one pass that unions equation[0] and equation[3] for every equality.","semanticSpec":{"intent":"Make a first pass that unions the two letters of every equality before any inequality is checked.","doneWhen":"This step is done when every equality merges its two letters in a pass that completes before inequality checking begins.","shouldFailWhen":"This step should fail if any inequality is checked before all equalities are merged, or if only explicitly paired letters merge without transitive grouping.","roles":["equality pass","letter pair","group merge","ordering"],"mustProve":["The code unions the first and last letter of each equality equation.","All equalities are merged in a pass that finishes before any inequality is tested."],"mustNotAccept":["Testing an inequality before every equality group is complete.","Only comparing explicit pairs without merging through shared letters."],"equivalentVariants":["Loop the equalities first, calling union on each one's two letters.","Use any equivalent two-phase order that completes all merges before the inequality checks."],"proofSnippets":[{"id":"py-eq-merge","language":"python","code":"    for equation in equations:\n        if equation[1] == '=':\n            x = ord(equation[0]) - ord('a')\n            y = ord(equation[3]) - ord('a')\n            union(x, y)"}]}},{"id":"check-inequalities","title":"Second pass: reject the contradictions","description":"Loop the inequalities and return false the moment a not-equal names two letters that share a root.","validation":{"type":"semantic","validator":"familyFact","params":[{"family":"union-find","fact":"returns_constraint_satisfiability_verdict_by_find","scope":"check-inequalities","readMode":"union-find-value-query-v1"}]},"commonMistakes":["Checking only direct parent values without find","Returning true before all inequalities are checked"],"hint":"If find(x) == find(y) for an inequality, the constraints are impossible.","semanticSpec":{"intent":"Make a second pass that returns false when an inequality's two letters share a root.","doneWhen":"This step is done when each inequality compares the two letters' roots and returns false on a match, with true returned only after all inequalities pass.","shouldFailWhen":"This step should fail if the code compares raw letters instead of roots, or returns true before every inequality is checked.","roles":["inequality pass","root comparison","contradiction","final verdict"],"mustProve":["The code compares the results of find on both letters of each inequality.","A matching pair of roots returns false, and true is returned only after all inequalities pass."],"mustNotAccept":["Comparing the raw letters instead of their roots.","Returning true before all inequalities have been checked."],"equivalentVariants":["Loop the inequalities, returning false as soon as find(x) equals find(y).","Use any equivalent same-group test that signals a contradiction when the roots match."],"proofSnippets":[{"id":"py-eq-check","language":"python","code":"    for equation in equations:\n        if equation[1] == '!':\n            x = ord(equation[0]) - ord('a')\n            y = ord(equation[3]) - ord('a')\n            if find(x) == find(y):\n                return False\n    return True"}]}}]},{"id":"complete","kind":"complete","chapter":"Code","eyebrow":"Take it with you","title":"What to carry forward","summary":"Merge every equality into groups, then a not-equal between two letters that share a root is the contradiction.","workspacePanel":"code","body":["Equalities partition the 26 letters into groups that must share a value, and union-find merges a whole chain in one touch instead of re-sweeping it.","Once the groups are final, an inequality is impossible exactly when its two letters land in the same group, so a second pass over the inequalities answers the question."],"takeaways":[{"title":"Same root means forced equal","body":"Two letters that reach the same root are forced equal through some equality chain, so an inequality between them cannot hold."},{"title":"Run the equality pass first","body":"Merging every equality before checking any inequality is what lets a late equality's contradiction surface; a single interleaved pass misses it."},{"title":"Union-find beats re-sweeping","body":"Linking roots merges an entire chain at once, turning the naive m-squared propagation into roughly linear work over 26 fixed groups."}],"nextAction":"Submit when you are ready. TraceCode will run the final checks against the code you wrote."}],"slidesOrigin":"authored"},"syntheticTestConfig":{"inputShape":"array","primaryParam":"equations","sizeMetric":"length","sizes":[2,4,8,16]}}
