All problems
0376EasyMathStringSimulation

Exposure Counter Sum

Tracked in this browser only
Write code

Trains the technique from

LeetCode 415Add Strings

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def add_strings(left: str, right: str) -> str:
Java
public String addStrings(String left, String right)
September 7
Apply