Company: Trilogy
Difficulty: medium
Codewriting A letter-substitution puzzle asks you to assign a single digit to every distinct letter so that a word-based addition statement becomes numerically true. Given such a puzzle as an array of strings crypt , count how many digit assignments make it hold. An assignment counts only if no two distinct letters map to the same digit, and no word's leading letter maps to zero (unless the word is a single character). crypt always has the shape [word1, word2, word3] , representing the equation word1 + word2 = word3 . Input Array of three non-empty strings containing only uppercase English letters. array.string crypt Output integer The count of digit assignments satisfying the equation. Constraints 1 ≤ crypt[i].length ≤ 35 Execution time limit: 0.5 seconds (cpp) Memory limit: 1 GB Examples Example 1: crypt = ["SEND", "MORE", "MONEY"] solution(crypt) = 1 Only a single digit mapping satisfies this equation: O = 0, M = 1, Y = 2, E = 5, N = 6, D = 7, R = 8, and S = 9 (9567 + 1085 = 10652)