Skip to content

Practice Verbal Arithmetic Puzzle

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1307
LeetCode Problem

Verbal Arithmetic Puzzle

Problem Statement

Assign one decimal digit to each distinct letter appearing in words and result, using the same digit for every occurrence and different digits for different letters. Each word and result must represent a number without a leading zero; a single-letter number may be zero. Return whether an assignment exists for which the sum of the numbers represented by words equals the number represented by result.

Source: Verbal Arithmetic Puzzle on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
words = ["SEND","MORE"], result = "MONEY"
Output
true

# Example 2

Input
words = ["SIX","SEVEN","SEVEN"], result = "TWENTY"
Output
true

# Example 3

Input
words = ["LEET","CODE"], result = "POINT"
Output
false

Constraints

2 <= words.length <= 5
1 <= words[i].length, result.length <= 7
words[i], result contain only uppercase English letters.
The number of different characters used in the expression is at most 10.

Related LeetCode Problems

Practice more problems similar to Verbal Arithmetic Puzzle.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.