Problem:
A cryptarithm is a mathematical puzzle for which the goal is to find the correspondence between letters and digits, such that the given arithmetic equation consisting of letters holds true when the letters are converted to digits.
You have an array of strings crypt, the cryptarithm, and an an array containing the mapping of letters and digits, solution. The array crypt will contain three non-empty strings that follow the structure: [word1, word2, word3], which should be interpreted as the word1 + word2 = word3 cryptarithm.
If crypt, when it is decoded by replacing all of the letters in the cryptarithm with digits using the mapping in solution, becomes a valid arithmetic equation containing no numbers with leading zeroes, the answer is true. If it does not become a valid arithmetic solution, the answer is false.
Note that number 0 doesn't contain leading zeroes (while for example 00 or 0123 do).
Example
Even though 054 + 091 = 145, 054 and 091 both contain leading zeroes, meaning that this is not a valid solution.
-Summary-
1. Convert the solution double list to the dictionary object to make key/value structure
2. For each word in the crypt, find each word in the solution to get the correct number value
3. After finding all the correct value for word1/word2/word3, compare them if word1+word = word3.
모든 문제에 대한 저작권은 CodeSignal 회사에 있습니다. [Copyright © 2020 BrainFights Inc. All rights reserved]
'CodeSignal > Interview Practice' 카테고리의 다른 글
[Linked Lists] removeKFromList (0) | 2020.05.30 |
---|---|
[Arrays] sudoku2 - Apple, Uber (0) | 2020.05.29 |
[Arrays] rotateImage - Amazon, Microsoft, Apple (0) | 2020.05.29 |
[Arrays] firstNotRepeatingCharacter - Amazon (0) | 2020.05.29 |
[Arrays] firstDuplicate - Google (0) | 2020.05.29 |
댓글