PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving and data structure proficiency in computing the maximum rectangular area within a histogram-like array, focusing on contiguous segment analysis and range-based aggregation.

  • medium
  • Palo
  • Coding & Algorithms
  • Software Engineer

Find Maximum Rectangle in Bar Chart

Company: Palo

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

Given an array `heights` of `n` non-negative integers, where each value represents the height of a vertical bar in a bar chart and every bar has width `1`, find the maximum possible rectangular area that can be formed by choosing one or more consecutive bars. A rectangle spanning bars `i` through `j` has height equal to the minimum height among those bars and width `j - i + 1`. Return the maximum area. **Example 1:** ```text Input: heights = [2, 1, 5, 6, 2, 3] Output: 10 Explanation: The best rectangle spans the bars with heights 5 and 6, giving area 5 * 2 = 10. ``` **Example 2:** ```text Input: heights = [2, 4] Output: 4 ``` **Constraints:** - `1 <= n <= 100000` - `0 <= heights[i] <= 1000000000` - The answer fits in a 64-bit signed integer.

Quick Answer: This question evaluates algorithmic problem-solving and data structure proficiency in computing the maximum rectangular area within a histogram-like array, focusing on contiguous segment analysis and range-based aggregation.

Return the maximum rectangle area in a bar chart.

Constraints

  • Inputs are Python literals matching the function signature.
  • Return a deterministic exact-match value.

Examples

Input: ([2,1,5,6,2,3],)

Expected Output: 10

Explanation: Best rectangle area is 10.

Input: ([2,4],)

Expected Output: 4

Explanation: Best area is 4.

Input: ([0],)

Expected Output: 0

Explanation: Zero height gives zero area.

Hints

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Implement an Alert Execution Engine - Palo (medium)
  • Find minimum tanks to cover all houses - Palo (medium)
  • Implement three whiteboard coding tasks - Palo (easy)