Does an Injective Letter-to-Digit Sum Exist?

Quick Overview

Does an Injective Letter-to-Digit Sum Exist?. Assign each uppercase letter one decimal digit, with different letters assigned different digits.

Does an Injective Letter-to-Digit Sum Exist?

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Assign each uppercase letter one decimal digit, with different letters assigned different digits. Decode every left-side word and result as a number with no leading zero on a multi-digit number. Return whether the sum of all decoded words can equal the decoded result. ```cpp class Solution { public: bool isSolvable(vector<string>& words, string result); }; ``` ### Examples **Example 1:** ```text Input: words = ["A","A"], result = "B" Output: true Explanation: A=1 and B=2 produce1+1=2 with distinct digits. ``` **Example 2:** ```text Input: words = ["A","B"], result = "AA" Output: false Explanation: A cannot be0 because AA has two digits. The equation A+B=11*A would require B=10*A>=10. ``` ### Constraints - There are 2 to 5 addend words. - Each word and result has length 1 to 7 and uses uppercase English letters only. - At most 10 distinct letters occur in the whole equation. ### Contract considerations The result is solvability, not a chosen digit mapping, so different satisfying assignments do not create output freedom. ```hint Read the boundary condition Check repeated letters, digit uniqueness, and the distinction between a single zero digit and a leading zero in a longer word. ``` ### Boundary reminders The result is solvability, not a chosen digit mapping, so different satisfying assignments do not create output freedom.

Overview: Does an Injective Letter-to-Digit Sum Exist?. Assign each uppercase letter one decimal digit, with different letters assigned different digits.

Google logo
Google
Aug 22, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Assign each uppercase letter one decimal digit, with different letters assigned different digits. Decode every left-side word and result as a number with no leading zero on a multi-digit number. Return whether the sum of all decoded words can equal the decoded result.

class Solution {
public:
    bool isSolvable(vector<string>& words, string result);
};

Examples

Example 1:

Input: words = ["A","A"], result = "B"
Output: true
Explanation: A=1 and B=2 produce1+1=2 with distinct digits.

Example 2:

Input: words = ["A","B"], result = "AA"
Output: false
Explanation: A cannot be0 because AA has two digits. The equation A+B=11*A would require B=10*A>=10.

Constraints

  • There are 2 to 5 addend words.
  • Each word and result has length 1 to 7 and uses uppercase English letters only.
  • At most 10 distinct letters occur in the whole equation.

Contract considerations

The result is solvability, not a chosen digit mapping, so different satisfying assignments do not create output freedom.

Boundary reminders

The result is solvability, not a chosen digit mapping, so different satisfying assignments do not create output freedom.