Date: 2026-06-06
Time: 15:44
check-if-word-equals-summation-of-two-words/solution.pyThis file solves LeetCode 1880. It contains both the solution and its tests in a single module. The problem defines a letter-to-digit mapping where 'a'=0, 'b'=1, ..., 'j'=9, converts each word into a number by concatenating those digits, and checks whether firstWord + secondWord == targetWord under that encoding.
Solution.isSumEqual — The sole public method. Takes three strings restricted to 'a'–'j' and returns a boolean.
wordtonum (nested closure) — Converts a word to its numeric value. For each character, it computes ord(c) - ord('a') to get a digit 0–9, joins the digit strings, then parses the result as an integer. For example, "acb" → "021" → 21.
TestSolution — Seven test cases covering the LeetCode examples, single-character inputs, boundary values ('a' = 0, 'j' = 9), and an all-zeros case.
wordtonum is defined inside isSumEqual rather than as a method or module-level function. This scopes the utility to the only place it's used.digit * 10^position arithmetically, the code builds a digit string and calls int(). This is idiomatic Python for multi-digit construction and avoids manual place-value math.Imports: Only unittest from the standard library — no external dependencies.
Imported by: The test_solution.py in this same directory imports from this file. The massive "Imported By" list in the prompt is misleading — those are other problems' test files importing unittest, not this module. The actual dependency graph for this file is trivial.
1. isSumEqual is called with three strings.
2. Each string passes through wordtonum: character → ord delta → string digit → join → int().
3. The two numeric results are summed and compared to the third via ==.
4. A single boolean is returned.
There are no loops beyond the generator expressions inside wordtonum. The entire computation is O(n) in total characters across all three words.
'a'–'j'. Characters outside this range would produce multi-digit values per character (e.g., 'k' → 10), which still works numerically but changes the semantics — "ka" would become "100" (100), not a two-digit number. This matches the LeetCode constraint that inputs are restricted to 'a'–'j'.int("021") → 21 in Python. The word "aab" maps to "001" → 1, which is correct per the problem definition.None. The function trusts its inputs per the LeetCode contract. Empty strings would produce int("") which raises ValueError, but the problem guarantees 1 <= len(word) <= 8.