Skip to content

Practice Check if Word Equals Summation of Two Words

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#1880
LeetCode Problem

Check if Word Equals Summation of Two Words

Problem Statement

The letter value of a letter is its position in the alphabet starting from 0 (i.e. 'a' -> 0, 'b' -> 1, 'c' -> 2, etc.). The numerical value of some string of lowercase English letters s is the concatenation of the letter values of each letter in s, which is then converted into an integer. You are given three strings firstWord, secondWord, and targetWord, each consisting of lowercase English letters 'a' through 'j' inclusive. Return true if the summation of the numerical values of firstWord and secondWord equals the numerical value of targetWord, or false otherwise.

Source: Check if Word Equals Summation of Two Words on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
firstWord = "acb", secondWord = "cba", targetWord = "cdb"
Output
true

# Example 2

Input
firstWord = "aaa", secondWord = "a", targetWord = "aab"
Output
false

# Example 3

Input
firstWord = "aaa", secondWord = "a", targetWord = "aaaa"
Output
true

Constraints

1 <= firstWord.length, secondWord.length, targetWord.length <= 8
firstWord, secondWord, and targetWord consist of lowercase English letters from 'a' to 'j' inclusive.

Related LeetCode Problems

Practice more problems similar to Check if Word Equals Summation of Two Words.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.