Letter Pattern Sum
Updated
Problem statement
Given a string of digits digits and a letter pattern pattern that contains one '+', cut digits into two numbers the way the pattern shows and return their sum.
Each letter in pattern stands for the next digit of digits, in order. The letters before '+' take the first digits and form the first number. The letters after '+' take the remaining digits and form the second number. A number may start with zeros and is read as its usual value, so "007" is 7.
Function
letterPatternSum(digits: String, pattern: String) → longExamples
Example 1
digits = "4821"pattern = "ab+cd"return = 69Two letters before '+' take "48", and two letters after it take "21". 48 + 21 = 69.
Example 2
digits = "90005"pattern = "a+bcde"return = 14The first number is 9. The second is "0005", which is 5. 9 + 5 = 14.
Example 3
digits = "2026"pattern = "xyz+w"return = 208Any letters can be used. Three letters take "202" and one letter takes "6". 202 + 6 = 208.
Constraints
2 <= digits.length <= 18digitsconsists only of the characters'0'to'9'.patternconsists of lowercase English letters and exactly one'+', which is not the first or last character.- The number of letters in
patternequalsdigits.length.
More Bank of America Online Assessment questions
- Return Exact Cash Register ChangeOA · Seen Aug 2026
- Sum Skipping Multiples of 7OA · Seen Nov 2025
- Wildcard Substring MatchOA · Seen Nov 2025
- Maximum String BeautyOA · Seen Sep 2024
- Merge Point of Two Linked ListsOA · Seen Oct 2023
- Remove Duplicates from a ListOA · Seen Oct 2023
- Pairs with Target Sum in a Sorted ArrayOA · Seen Oct 2023
- Count Level-Order Traversals of a TreeOA · Seen Sep 2023
- Count Set BitsOA · Seen Sep 2023
- Count Pairs with Sum KOA · Seen Jun 2023
Similar questions at other companies
- Identification Number Check DigitAbridge · OAAbridge interview questions
- Count Substrings With Identical CharactersVirtu Financial · OAVirtu Financial interview questions
- Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
- Is This Date a Weekend?Salesforce · OASalesforce interview questions
- Triple-Position Alphabet EncodingArm · OA
- Closest ColorTwo Sigma · OATwo Sigma interview questions
- Prime Number From a StringAdobe · OAAdobe interview questions
- Sum Integer StringsIntuit · OAIntuit interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions
- Count Times Using at Most Two DigitsLSEG · OALSEG interview questions