Brain-Score 92/100 TECH Hello Interview · 1:47

Largest Rectangle in Histogram

3-Second Blueprint (English)

  1. Expanding outward from each histogram bar to locate its nearest shorter left and right boundaries takes O(n²) time in the worst case.
  2. Keeping a monotonically increasing stack of bar indices defers area checks while heights climb until a shorter bar forms a right wall.
  3. Popping taller bars uses the new stack top as the left wall to compute width, pushing and popping every bar once for an O(n) linear pass.
Monotonic StackLinear O(n) SweepBoundary Index TrackingSentinel Flush

3-Sekunden-Fazit (Deutsch)

  1. Von jedem Histogrammbalken einzeln nach links und rechts bis zum nächsten kleineren Balken zu suchen, erfordert im Worst Case O(n²) Zeit.
  2. Ein monoton wachsender Index-Stack sammelt steigende Balken, bis ein kürzerer Balken auftaucht und deren rechte Rechteckgrenze markiert.
  3. Beim Poppen liefert das neue Stack-Ende die linke Grenze; jeder Balken wird nur einmal verarbeitet, was die Laufzeit auf O(n) senkt.
Monotoner StackLineare O(n)-LaufzeitGrenzindex-TrackingSentinel-Abschluss

Note / Hinweis: Blueprints are AI-generated educational summaries (0% Politics · 0% Religion · 0% Brainrot) and do not constitute medical, legal, or financial advice. / KI-generierte Zusammenfassung zu Bildungszwecken – ersetzt keine medizinische, rechtliche oder finanzielle Fachberatung.