Largest Rectangle in Histogram Problem Statement

You are given an array/list HEIGHTS of length N, where each element represents the height of a histogram bar. The width of each bar is considered to be 1.

Your task is to compute the area of the largest rectangle that can be formed within the bounds of the given histogram.

Example:

Input:
{2, 1, 5, 6, 2, 3}
Output:
10
Explanation:

In the given histogram, the largest rectangle possible has an area of 10.

Input:

The first line contains a single integer 'T’, representing the number of test cases. For each test case, the first line contains a single integer 'N' representing the number of elements in the array/list. The second line contains 'N' single space-separated integers, denoting the elements of the array/list HEIGHTS.

Output:

For each test case, output an integer that represents the area of the largest rectangle possible in the given histogram.

Constraints:

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 10^6
  • 0 ≤ HEIGHTS[i] ≤ 10^9
  • Time Limit: 1 sec.
Note:

You do not need to print anything; it has already been taken care of. Just implement the given function.

AnswerBot
1y

The task is to find the largest rectangle possible in a given histogram and return its area.

  • Iterate through the histogram and maintain a stack to keep track of the indices of the bars in non-decreasin...read more

Help your peers!
Select
Add answer anonymously...

Texas Instruments Software Developer Intern interview questions & answers

A Software Developer Intern was asked Q. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more

Popular interview questions of Software Developer Intern

A Software Developer Intern was asked Q1. Meeting Rooms Allocation Problem Statement Stark Industry is planning to organiz...read more
A Software Developer Intern was asked Q2. Maximum Sum Rectangle Problem Given an M x N matrix of integers ARR, your task i...read more
A Software Developer Intern was asked Q3. Josephus Problem Statement Consider 'N' individuals standing in a circle, number...read more
Texas Instruments Software Developer Intern 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