This is illustrated by the first shaded area covering the first two buildings. Concerning dynamic programming there is a lot of resources, choose one. The largest rectangle is shown in the shaded area, which has area = 10 unit. Equal Stacks, here is my solution in java which can pass this testcase too.. static int equalStacks(int[] h1, int[] h2, int[] h3) { Stack s1=new Stack(); Stack< HackerRank concepts & solutions. area = height[top] * (stack.empty() ? We pop the top of the stack which holds top = 2 and compute the area of the rectangle area = height * 3 which produces area = 2 * 3 = 6. We pop the top of the stack into top = 5. The area == 12 > maxArea == 6 so maxArea = 12. GitHub Gist: instantly share code, notes, and snippets. Recommended: Please try your approach on first, before moving on to the solution. The height == 4 is greater than height == 3 so we push i == 7 and increment I == 8. The area is based on the height * length. The important item to understand is that for the first building the height was 4. Contribute to BlakeBrown/HackerRank-Solutions development by creating an account on GitHub. My Hackerrank profile.. The height is represented by the largest minimum in a segment defined by some i and j. Apparently this problem, under different names and constraints, has been around for decades. FileInputStream; import java. We only need to keep track of the bars that are not blocked. We pop the top of the stack into top = 3. import java.io.*;. Line 5. Hackerrank is a site where you can test your programming skills and learn something new in many domains.. We use cookies to ensure you have the best browsing experience on our website. The majority of the solutions are in Python 2. Don't worry. I was not able to find good descriptions even though I ran into text, tutorials and even videos solving this challenge. At this point the area from the first two rectangles is 3 * 2 = 6. Hackerrank. The class should have display() method, to print the width and height of the rectangle separated by space. Output Formateval(ez_write_tag([[300,250],'thepoorcoder_com-box-3','ezslot_4',102,'0','0'])); The output should consist of exactly two lines: In the first line, print the width and height of the rectangle separated by space. Given that area == 4 is less than maxArea == 6 the maxArea is left unchanged. Line 12. Given that the area not greater than the previous one (6), there is no reason to update the maxArea and it remains 6. Idea is to first find max continuous 1's Sort that stored matrix. We pop the top of the stack into top = 7. In order to better follow the algorithm, the showStack() method displays a line number. My initial approach did not use a stack. Given that area == 6 is greater than maxArea == 4 the maxArea is set to maxArea = area = 6. For a full description of the challenged and additional information regarding constrains and input data, please visit the HackerRank web site. There are tree methods. Given the array, nums= [2,3,6,6,5] we see that the largest value in the array is 6 and the second largest value is 5. So how the necessary information could be better managed? Save the source file in the corresponding folder in your forked repo. and explain why you chose them. The stack is not empty (it contains 4 entries). Now let’s discuss the output line by line to get a good understanding of the algorithm. This area is larger than 4 so we update the maxArea and set it to 6. Line 16. We then go to the second rectangle (height  == 3). The initial idea is to take the first rectangle (height  == 4) and set the current maxArea = 4. In the second line, print the area of the rectangle.