Sum Two Bounded Signed Integers

Quick Overview

Sum Two Bounded Signed Integers. Return the arithmetic sum of num1 and num2. Either input may be negative or zero; keep the original int-returning sum(int num1,int num2) method.

Sum Two Bounded Signed Integers

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Given the integers `num1` and `num2`, return their arithmetic sum using the supplied `int sum(int num1, int num2)` method. Either input may be negative or zero. ```cpp class Solution { public: int sum(int num1, int num2); }; ``` ### Examples **Example 1:** ```text num1 = 7, num2 = -9 Output: -2 Explanation: Adding a negative nine to seven gives negative two. ``` **Example 2:** ```text num1 = -4, num2 = -6 Output: -10 Explanation: Two negative addends produce their signed sum. ``` ### Constraints - `-100 <= num1,num2 <= 100`. ### Clarifying Questions The task asks for integer addition, without any restriction against the addition operator. ```hint Inspect the structure What is the largest possible magnitude of the result under these input bounds? ``` ### Reasoning checkpoints - Return the mathematical signed sum for every input in the specified range. - Explain why the chosen return type can represent all possible results. - Keep the native method interface without adding restrictions on the allowed arithmetic operations. ### Optional extensions How would you guard the addition if arbitrary signed 32-bit inputs replaced these bounds?

Overview: Sum Two Bounded Signed Integers. Return the arithmetic sum of num1 and num2. Either input may be negative or zero; keep the original int-returning sum(int num1,int num2) method.

Google logo
Google
Aug 6, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Given the integers num1 and num2, return their arithmetic sum using the supplied int sum(int num1, int num2) method. Either input may be negative or zero.

class Solution {
public:
    int sum(int num1, int num2);
};

Examples

Example 1:

num1 = 7, num2 = -9
Output: -2
Explanation: Adding a negative nine to seven gives negative two.

Example 2:

num1 = -4, num2 = -6
Output: -10
Explanation: Two negative addends produce their signed sum.

Constraints

  • -100 <= num1,num2 <= 100 .

Clarifying Questions Guidance

The task asks for integer addition, without any restriction against the addition operator.

Reasoning checkpoints

  • Return the mathematical signed sum for every input in the specified range.
  • Explain why the chosen return type can represent all possible results.
  • Keep the native method interface without adding restrictions on the allowed arithmetic operations.

Optional extensions

How would you guard the addition if arbitrary signed 32-bit inputs replaced these bounds?