Add Two Integers
Real-world version: Combine Two Stock CorrectionsThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def sum(first: int, second: int) -> int:public int sum(int first, int second)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 10 test cases: 10 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