Add Strings
Real-world version: Exposure Counter SumThe statement here is our own: the same inputs, outputs and technique.
An archival telescope keeps its shutter counters as decimal text, because the running totals outgrow every machine word the logger owns. You are handed two such counters, left and right, each a string of digits with no leading zeros unless the counter itself is "0".
Return the sum of the two counters, again as a digit string with no leading zeros.
The logger has no arbitrary-precision arithmetic available, so you must stay on the characters: do not convert left or right into a built-in big integer, do not call a library routine that parses a numeric string for you, and do not hand the work to a big-number package.
Examples
Example 1
- Input
- left = "907", right = "35"
- Output
- "942"
The two counters total 942, reported in the same digit-string form.
Example 2
- Input
- left = "6", right = "3994"
- Output
- "4000"
The total is 4000, which is as many digits as the longer counter.
Example 3
- Input
- left = "88", right = "12"
- Output
- "100"
The total is 100, one digit longer than either counter.
Example 4
- Input
- left = "40", right = "0"
- Output
- "40"
Adding the zero counter leaves the other counter unchanged.
Constraints
- 1 <= left.length, right.length <= 10^4
- left and right consist of digits only.
- left and right have no leading zeros except for the single digit 0 itself.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def add_strings(left: str, right: str) -> str:public String addStrings(String left, String right)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 9 test cases: 9 passed
- Passed: 4 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's