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
Zero width
7*3=21
Unit square
4*5=20
Square
Algorithm Flow

Solution Approach
Multiply width by height and return the result.
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
class Solution {
public int solution(int w, int h) {
return w*h;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this Challenge.
