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
Verbal Arithmetic Puzzle: SEND + MORE = MONEYSEND+MORE=MONEYEach letter represents a unique digit 0-9No leading zeros allowed (S ≠ 0, M ≠ 0)9567+1085=10652S=9,E=5,N=6,D=7M=1,O=0,R=8,E=5M=1,O=0,N=6,E=5,Y=2Output: true (Valid assignment found)
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
Asked in
Google 12 Amazon 8 Microsoft 6 Facebook 4
28.0K Views
Medium Frequency
~35 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen