Verbal Arithmetic Puzzle - Problem
Given an equation represented by words on the left side and the result on the right side.
You need to check if the equation is solvable under the following rules:
- Each character is decoded as one digit (0-9)
- No two characters can map to the same digit
- Each word and result are decoded as numbers without leading zeros
- Sum of numbers on the left side equals the number on the right side
Return true if the equation is solvable, otherwise return false.
Input & Output
Example 1 — Basic Solvable Case
$
Input:
words = ["SEND", "MORE"], result = "MONEY"
›
Output:
true
💡 Note:
One valid assignment: S=9, E=5, N=6, D=7, M=1, O=0, R=8, Y=2. This gives 9567 + 1085 = 10652, which is valid.
Example 2 — Leading Zero Violation
$
Input:
words = ["SIX", "SEVEN", "SEVEN"], result = "TWENTY"
›
Output:
true
💡 Note:
Multiple characters make this complex, but a valid assignment exists where no leading character maps to 0.
Example 3 — Impossible Case
$
Input:
words = ["THIS", "IS"], result = "TOO"
›
Output:
false
💡 Note:
No digit assignment can make THIS + IS = TOO work while satisfying all constraints.
Constraints
- 2 ≤ words.length ≤ 5
- 1 ≤ words[i].length ≤ 7
- 1 ≤ result.length ≤ 7
- words[i] and result contain only uppercase English letters
- The number of different characters used in the expression is at most 10
Visualization
Tap to expand
Understanding the Visualization
1
Input
Words equation: SEND + MORE = MONEY
2
Process
Assign unique digits to each letter
3
Output
Return true if valid assignment exists
Key Takeaway
🎯 Key Insight: Use backtracking to efficiently explore digit assignments while respecting leading zero constraints
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code