Problem · String
Concatenate Digit-wise Sums
Learn this problemProblem 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) → StringExamples
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
aandbare 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
4seconds and a memory limit of1 GB.
More Tiktok problems
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
- Count House Segments After DestructionOA · Seen Aug 2026
- Debugger Breakpoint ActionsOA · Seen Aug 2026
- Distribution Center Package AllocationOA · Seen Aug 2026
- Find All Local PeaksOA · Seen Aug 2026
- Minimum Height Difference Between Distant PeaksOA · Seen Aug 2026
- Minimum Operations for Stepwise StructuresOA · Seen Aug 2026
- Rating Level After ChangesOA · Seen Aug 2026