Count Unique Rectangles in Grid

Given a grid with 'M' rows and 'N' columns, calculate the total number of unique rectangles that can be formed within the grid using its rows and columns.

Input:

The first line contains an integer T, the number of test cases.
Each test case consists of a single line with two space-separated integers, M (number of rows) and N (number of columns).

Output:

For each test case, output a single integer representing the number of unique rectangles that can be formed in the specified grid.

Example:

Input:
2
3 4
2 2
Output:
60
9
Explanation:

For a grid of 3 rows and 4 columns, a total of 60 rectangles can be formed.

Constraints:

  • 1 <= T <= 100
  • 1 <= N, M <= 104
  • Time limit: 1 second

Note:

No need to print the output explicitly; implement the function to return it.

AnswerBot
4mo

Calculate the total number of unique rectangles that can be formed within a grid using its rows and columns.

  • Iterate through all possible combinations of rows and columns to calculate the number of uni...read more

Help your peers!
Select
Add answer anonymously...

Snapdeal Software Developer interview questions & answers

A Software Developer was asked Q. Given two linked lists that merge at a point, find the merging point.
A Software Developer was asked Q. Given an M x N matrix, how many rectangles are there?
A Software Developer was asked Q. Find a four-digit number in the form aabb that is a perfect square.

Popular interview questions of Software Developer

A Software Developer was asked Q1. Given two linked lists that merge at a point, find the merging point.
A Software Developer was asked Q2. Given an M x N matrix, how many rectangles are there?
A Software Developer was asked Q3. Find a four-digit number in the form aabb that is a perfect square.
Snapdeal Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits