Code Logo

Rectangle Area

Published at25 Jul 2026
Geometry Easy 4 views
Like0

Given the width and height of a rectangle (both positive integers), compute its area using the formula A = width × height. The result is an integer.

For example, a rectangle with width 5 and height 3 has area 5 × 3 = 15. A rectangle with width 10 and height 10 has area 100 (a square). If either dimension is 0, the area is 0. Width and height are guaranteed to be non-negative integers.

This is the simplest geometric calculation: area equals the product of two perpendicular sides. The rectangle area formula is foundational for computing floor space, land plots, screen dimensions, and virtually any rectangular region. Understanding this formula is a prerequisite for more advanced topics like computing surface area of 3D shapes or integrating over rectangular regions in calculus.

In programming terms, this is a straightforward multiplication of two integers. The result fits within a standard 32-bit integer for the input ranges used in this challenge. No special handling is needed beyond basic multiplication.

The only edge case is when width or height is 0, in which case the area is 0. This follows naturally from the multiplication: any number multiplied by 0 is 0, so the formula handles it automatically.

Example Input & Output

Example 1
Input
0,5
Output
0
Explanation

Zero width

Example 2
Input
7,3
Output
21
Explanation

7*3=21

Example 3
Input
1,1
Output
1
Explanation

Unit square

Example 4
Input
4,5
Output
20
Explanation

4*5=20

Example 5
Input
10,10
Output
100
Explanation

Square

Algorithm Flow

Recommendation Algorithm Flow for Rectangle Area
Recommendation Algorithm Flow for Rectangle Area

Solution Approach

Multiply width by height and return the result.

function solution(width, height) {
  return width * height;
}

This is a direct translation of the geometric formula A = w × h into code. The multiplication operator works on integers natively in all supported languages.

The time complexity is O(1) and space complexity is O(1).

Best Answers

java
class Solution {
    public int solution(int w, int h) {
        return w*h;
    }
}