All challenges
Easy 1 solved 100.0% acceptance

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

Problem

A rectangle has two sides of length width and two sides of length height. Its perimeter is the total length of all four sides.

Implement rectangle_perimeter(width, height).

Input

width: The width of the rectangle. height: The height of the rectangle.

Output

Return the perimeter as an integer.

Constraints

1 ≤ width, height ≤ 1,000,000

Examples

Example 1
Input:
width = 3
height = 5

Expected output:
expected = 16
Input:
long long width = 3;
long long height = 5;

Expected output:
long long expected = 16;
Input:
long width = 3;
long height = 5;

Expected output:
long expected = 16;

Explanation

Two sides of 3 and two sides of 5: 3 + 3 + 5 + 5 = 16.

Example 2
Input:
width = 7
height = 7

Expected output:
expected = 28
Input:
long long width = 7;
long long height = 7;

Expected output:
long long expected = 28;
Input:
long width = 7;
long height = 7;

Expected output:
long expected = 28;

Explanation

A square is a rectangle too: 4 × 7 = 28.

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

Spoiler alert: 1 full solution below Try solving it yourself first. You can still peek at other developers' code and AI reviews. Sign in and solve the challenge to join the discussion.