Problem · String

Concatenate Digit-wise Sums

Learn this problem
EasyTiktok logoTiktokINTERNOA
See Tiktok hiring insights

Problem statement

You are given two non-empty strings a and b consisting of decimal digits.

Right-align the strings. For each aligned position, add the corresponding digits. If one string has no digit at that position, use the digit from the other string as the sum for that position.

Return a string formed by concatenating these per-position sums from the leftmost aligned position to the rightmost. A sum such as 18 contributes both characters 1 and 8; there is no carry between positions.

Function

concatenateDigitSums(a: String, b: String) → String

Examples

Example 1

a = "99"b = "99"return = "1818"

The two aligned positions each contain 9 + 9 = 18. Concatenating the two sums gives "1818".

Example 2

a = "11"b = "9"return = "110"

The leftmost position contains only 1, and the rightmost position has 1 + 9 = 10. Concatenating 1 and 10 gives "110".

Constraints

  • a and b are non-empty strings of decimal digits without leading zeroes.
  • Digits are aligned from the right, and every position is summed independently without carrying.
  • The visible source states that O(max(a.length, b.length)^2) time fits within the execution limit.
  • The visible source lists a Python execution-time limit of 4 seconds and a memory limit of 1 GB.

More Tiktok problems

drafts saved locally
public String concatenateDigitSums(String a, String b) {
    // Write your code here.
}
a"99"
b"99"
expected"1818"
checking account