FastPrepMaximum Capped Histogram Area After One Removal
Problems/Maximum Capped Histogram Area After One Removal

Maximum Capped Histogram Area After One Removal

Myntra logoMyntra● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Myntra online assessment for interns. The report names a variant of Largest Rectangle in Histogram. One building must be removed, and the area has a cap. It leaves out what removal and the cap mean exactly, the limits, and the examples. We filled those in.

Our version is about 88% the same as the reported question.

You are given positive building heights heights and a positive area limit limit. Remove exactly one building; the buildings on its two sides become adjacent.

For the remaining histogram, compute its ordinary largest axis-aligned rectangle area. A removal is eligible only when that largest area is at most limit. Return the greatest eligible largest-rectangle area over all removals. If no removal is eligible, return 0.

Function

maxCappedAreaAfterRemoval(heights: long[], limit: long) → long

Examples

Example 1

heights = [2,1,5,6,2,3]limit = 10return = 10

Removing the height 1 leaves [2, 5, 6, 2, 3], whose largest rectangle has area 10. It is eligible and no eligible removal produces a larger area.

Example 2

heights = [2,4,2]limit = 6return = 4

Every possible removal leaves a two-building or one-building histogram whose largest rectangle area is 4.

Example 3

heights = [3,3,3]limit = 4return = 0

After any removal, the two remaining buildings form a largest rectangle of area 6, so no removal is eligible.

Constraints

  • 1 <= heights.length <= 2000.
  • 1 <= heights[i] <= 10^9.
  • 1 <= limit <= 10^18.

More Myntra interview questions

  • Detect a Server RAM Capacity BreachONSITE INTERVIEW · Seen May 2026
  • Minimum Route Reversals to Warehouse ZeroONSITE INTERVIEW · Seen May 2026
  • Minimum Swaps to Group Values at Most KONSITE INTERVIEW · Seen May 2026
  • Smallest Binary-Digit MultipleONSITE INTERVIEW · Seen May 2026

Similar questions at other companies

  • Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
  • Sum of Subarray MinimumsNVIDIA · OANVIDIA interview questions
  • Shopkeeper Final Price SummaryMicrosoft · OAMicrosoft interview questions
  • Nested Recipe Blocks (Game Adaptation)Roblox · OARoblox interview questions
  • Steps to the Next Higher Value in a CircleRippling · OARippling interview questions
  • Shopkeeper Final PriceUber · OAUber interview questions
  • Predict AnswerAmazon · OA
  • Retention Policy CollisionBox · OABox interview questions
  • Longest Prefix-Valid Binary SubarrayHackerRank · OAHackerRank interview questions
  • Sum of Subarray RegionsPatreon · OA
All Myntra interview questionsSee Myntra hiring insights
Saved
class Solution {
    public long maxCappedAreaAfterRemoval(long[] heights, long limit) {
        // Return the best eligible largest-rectangle area.
    }
}
Checking account…