← 返回 twosigma 的题目列表Add Two Strings with a Single-Digit Adder
类型:qbank
Given only a helper that can add two single digits, implement addition for two non-negative integer strings. The live round expects careful carry handling and time/space complexity explanation.
Requirements
You are given a function that can add two single digits. Use it to implement addition for two number strings.
Expected behavior:
Inputs are strings representing non-negative integers.
Add from right to left.
Maintain carry.
Return the sum as a string.
Explain time and space complexity.
Notes
This is a straightforward implementation round, but it appears inside a broader QR / statistics interview day, so do not ignore coding basics.
Clarify whether inputs may contain leading zeros, signs, decimals, or invalid characters. The natural baseline assumes non-negative integer strings.
Time is O(max(m, n)); output space is O(max(m, n)).
Preparation
Write the reverse-iteration implementation without converting the full strings to integers.
Test 0 + 0, different lengths, final carry, leading zeros, and very long inputs.
Practice giving the complexity answer while coding, since candidates were explicitly asked to explain it.