Solve a Word-Sum Cryptarithm by Assigning Digits to Letters

Last updated: November 29, 2026

Quick Overview

Given words added together and a result word (for example SEND + MORE = MONEY), assign distinct digits to letters so the sum holds and no multi-letter word starts with zero. Return a valid assignment or report that none exists.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


Given words added together and a result word (for example SEND + MORE = MONEY), assign distinct digits to letters so the sum holds and no multi-letter word starts with zero. Return a valid assignment or report that none exists.

A Google onsite constraint-satisfaction problem. Brute force over 10!/(10-k)! assignments works but is slow; the interviewer wants weighted coefficients or column-by-column search with carries, plus the leading-zero rule.

What the Interviewer Expects
  • Reduces the equation to a weighted sum of letters equal to zero
  • Assigns letters in order of largest absolute weight to prune early
  • Bounds the remaining sum to cut impossible branches
  • Enforces distinct digits and non-zero leading letters
  • Discusses column-wise search with carries as an alternative
Key Topics to Cover
Backtracking
Constraint satisfaction
Pruning
Weighted sums
Puzzles
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you count all solutions instead of returning one?
  • How would you support subtraction and multiplication?
  • How would the column-by-column version prune differently?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list of addend words and a result word, uppercase letters, at most 10 distinct letters.
  • Output: a dict letter -> digit satisfying the sum, or None.
  • Leading letters of words with length > ...
High-Level Design

Turn the puzzle into one linear equation. Each letter gets a weight: for an addend, add 10^p at each position p from the right; for the result, subtract. A valid assignment satisfies `sum(weight[L] * ...


Submit Your Answer
Markdown supported