filmov
tv
Programming Interview 39: Find Largest Rectangle Size in a Histogram in linear time
![preview_player](https://i.ytimg.com/vi/E5C5W6waHlo/maxresdefault.jpg)
Показать описание
Step by step to crack Programming Interview questions Q39: Find Largest Rectangle Size in a Histogram in linear time.
E.g. in histogram {2,4,2,1}, the largest rectangle starts from 1st until 3rd with height of 2. The largest size is thus 6.
Solution:
Use Stack to keep track of height and start indexes
Compare current height with previous one
#1: current Larger than previous (top of height stack)
Push current height & index as candidate rectangle start position
#2: current EQUALS previous
Ignore, as largest rectangle will start from previous with same height
#3: current is less than previous
Need keep popping out previous heights, and compute the candidate rectangle with height and width (current index MINUS previous index)
Push the height and index (appropriate position) to stacks
E.g. in histogram {2,4,2,1}, the largest rectangle starts from 1st until 3rd with height of 2. The largest size is thus 6.
Solution:
Use Stack to keep track of height and start indexes
Compare current height with previous one
#1: current Larger than previous (top of height stack)
Push current height & index as candidate rectangle start position
#2: current EQUALS previous
Ignore, as largest rectangle will start from previous with same height
#3: current is less than previous
Need keep popping out previous heights, and compute the candidate rectangle with height and width (current index MINUS previous index)
Push the height and index (appropriate position) to stacks
Programming Interview 39: Find Largest Rectangle Size in a Histogram in linear time
Top 5 Algorithms for Coding Interviews
Find the largest number in an array |JavaScript Interview Question | Coding Interview Question
#39 JS Interview Question | JS Coding questions #javascript #interviewpreparation #frontend
Coding Interview Tutorial 39: Search a 2D Matrix [LeetCode]
Programming Interview:Dynamic Programming:Maximum-sum contiguous array - kadane's algorithm
Amazon Coding Interview Question | Leetcode 39 | Combination Sum
Coding Interview Problem - Largest Rectangle In Histogram
Tesla Coding Interview Question! - Maximum Number of Balloons - Leetcode 1189
Javascript interview questions and answers - 39 | Javascript Interview Questions Answers Coding 2023
Top 60 Programming interview questions with answer - CRACK INTERVIEW
T4TEQ Weekly Coding Challenge - 39 - Google Interview question. Find the Missing Number
2.Max Length chain | Dynamic programming | Python | Must do coding interview questions
Programming Interview 48: Compute Largest Contiguous Subsequent Product (LSP) in Linear Time
Contiguous Array Explained: Ace Your LeetCode Coding Interview With Coding Card Sharp
Amazon Interview Question Leetcode 57 Insert Interval #coding #codinginterview #jobinterview
Python Coding Interview Question | Second largest number in Python
Top 5 String problems for Programming interviews | #programming #coding #string #shorts
Amazon Coding Interview Question - Recursive Staircase Problem
Top 5 Most Common Graph Algorithms for Coding Interviews
Coding Interviews Be Like Pt. 3
Programming Interview 36: Find (kth largest) Kth item from array after sorting in ascending order
How to Avoid the Biggest Coding Interview Mistakes (FAANG)
Top 7 Algorithms for Coding Interviews Explained SIMPLY
Комментарии