Magicsheet logo

Verbal Arithmetic Puzzle

Hard
58.7%
Updated 6/1/2025

Verbal Arithmetic Puzzle

What is this problem about?

The "Verbal Arithmetic Puzzle" interview question is a "Hard" difficulty problem that asks you to solve a cryptarithmetic puzzle. You are given a list of words and a result word. Each unique character in these words must be assigned a unique digit (0-9) such that the sum of the input words equals the result word. Also, no word can have a leading zero if its length is greater than one.

Why is this asked in interviews?

Atlassian and Google use the "Verbal Arithmetic Puzzle" coding problem to test a candidate's proficiency with "Backtracking interview patterns" and pruning techniques. This problem has a massive search space, so simply trying all permutations will fail. It evaluates your ability to optimize recursion and handle constraints effectively.

Algorithmic pattern used

The core pattern is "Backtracking with Pruning." You map each character to a digit. A smart way to solve this is to work column by column from right to left (the units place, the tens place, etc.), similar to how you perform long addition. This allows you to check if the current sum matches the result's digit at that position immediately, allowing you to "prune" (stop) branches of the recursion early.

Example explanation

Puzzle: ["SEND", "MORE"], Result: "MONEY"

  1. Unique letters: S, E, N, D, M, O, R, Y.
  2. Start at the last column: D + E = Y (or Y + 10).
  3. Try digits for D, E, Y. If D=7, E=5, then 7+5=12, so Y=2 and carry=1.
  4. Move to next column: N + R + carry = E.
  5. Continue until all letters are assigned or a constraint is violated.
  6. Check leading zero constraints (S and M cannot be 0).

Common mistakes candidates make

The most common mistake is not pruning the search tree, leading to a TLE (Time Limit Exceeded) error. Another is forgetting the "unique digit" constraint (two different letters cannot represent the same number). Candidates also often struggle with managing the "carry" value between columns in the recursive calls.

Interview preparation tip

For the "Verbal Arithmetic Puzzle" coding problem, pre-calculating the power-of-10 weight for each character can simplify the logic. For example, in "SEND", S has weight 1000, E has 100, N has 10, and D has 1. This allows you to represent the puzzle as a single equation.

Similar Questions