All problems
0371EasyMath

Combine Two Stock Corrections

Tracked in this browser only
Write code

Trains the technique from

LeetCode 2235Add Two Integers

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.

A stock sheet records every correction to a line as one signed whole number: a positive value adds units to the line, a negative value removes them, and zero leaves the line where it was.

Two corrections have been filed against the same line, first and then second. Whoever filed them wants to replace both with a single correction that moves the line to exactly the same place.

Return that single correction.

Examples

Example 1

Input
first = 7, second = -3
Output
4

Adding 7 units and then removing 3 leaves the line 4 units above where it started.

Example 2

Input
first = -25, second = -40
Output
-65

Both corrections remove units, so the line ends up 65 units below where it started.

Example 3

Input
first = -100, second = 100
Output
0

The second correction undoes the first exactly, so the replacement correction is 0.

Example 4

Input
first = 0, second = 58
Output
58

The first correction leaves the line alone, so only the second one has any effect.

Constraints

  • -100 <= first, second <= 100

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 sum(first: int, second: int) -> int:
Java
public int sum(int first, int second)
September 7
Apply