LeetCode 84. Largest Rectangle in Histogram in Java

In this post we will solve LeetCode 84. Largest Rectangle in Histogram problem using the Java programming language and the VSCode IDE on a Windows computer.

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1, 
return the area of the largest rectangle in the histogram.


o 1 <= heights.length <= 10^5
o 0 <= heights[i] <= 10^4

Related Topics:
* Array
o Stack
* Monotonic Stack

We are given an array representing a histogram. The width of each bar holding a value is 1 unit. We are asked to return the area of the largest rectangle in the histogram. Continue reading “LeetCode 84. Largest Rectangle in Histogram in Java”

LeetCode 402. Remove K Digits in Java

In this post we will solve the LeetCode 402 Remove K Digits problem.

Given string num representing a non-negative integer num, and an integer k, 
return the smallest possible integer after removing k digits from num.


o 1 <= k <= num.length <= 10^5
o num consists of only digits.
o num does not have any leading zeros except for the zero itself.

If interested in this problem I suggest you read the current description in the LeetCode website. The requirements may be refined since this post. Continue reading “LeetCode 402. Remove K Digits in Java”

Codility_ problem Fish in Java

In this post we will attempt to solve the Codility_ problem Fish (https://app.codility.com/programmers/lessons/7-stacks_and_queues/fish/) in which we are given N voracious fish are moving along a river. Calculate how many fish are alive. Continue reading “Codility_ problem Fish in Java”

Stone Wall

Good day! Hope all is well in your neck of the woods. My wife left lunch in the oven and ran to the dentist office. She left the oven on. Not sure when I should shut it down. I think I will do it right now before the food gets burned. When she gets back we can turn on the oven back if needed.

OK, the oven is off. It is 01:00 PM. I am starving. Hope my wife returns shortly so we can have lunch. Continue reading “Stone Wall”

Middle of the Linked List

I am working on the last 2-hour block of the day. My wife was trying to make a payment for our Internet service, but she needs a number that can only be found in a previous bill receipt. Apparently she can not find one, so at the end of the workday we will go to make a payment in person and will hopefully keep the receipt, so this situation does not repeat. Continue reading “Middle of the Linked List”

Memory Pools – O(1) Storage

Happy Tuesday! Hope you had a nice long weekend. Labor Day in Minnesota marks the official summer season. The Minnesota State Fair ended yesterday. It flags the start of public schools and public universities in our state. In general, private schools and universities start a few weeks earlier.

My wife and I did not have too many things to do over the long weekend. Pretty much we did some grocery shopping, walking, and cook meals. We did watch on Amazon Prime an interesting and somewhat older movie. Trumbo was released on DVD in September 15, 2009. The movie provides interesting facts about the Hollywood Blacklist. It describes interesting and dark moments for liberty and freedom in the USA. Hopefully we have learned something and it will not repeat. The black list has nothing to do with African Americans. These events are associated with white people that disagreed with the main stream ideas of the time. The movie starts in 1947, a few years after the WWII ended. When you get a chance spend a couple hours watching this movie.

On a separate note, this post has as of right now 9,037 subscribers. Thank you very much!!! Continue reading “Memory Pools – O(1) Storage”

Reverse Operations Revisited

Yesterday morning I attended a one hour webinar sponsored by the Association for Computing Machinery titled ACM Queue Case Study Q&A: Always-On Time-Series Database. It was very interesting. There was no presentation segment. There were only questions. The presenter, Theo Schlossnagle which is the founder of Circonus was very eloquent and seems very versed in the technology and their products.

During the conference I made several notes and searched for several topics that I found of interest. I will be reading the associated pages later this week. Continue reading “Reverse Operations Revisited”

Balance Brackets

It is pitch dark in the Twin Cities of Minneapolis and St. Paul. Before calling it a day I decided to try one more practice problem from the Facebook web site. Balance Brackets is a very common problem. In general the idea is that you are given a set of brackets and are sked to determine if the brackets are balanced.

I knew I have solved similar versions of the problem. When done with the code I move to a different computer and type in the contents for the post. I looked up in my web site for the string “balanced brackets” and found Balanced Brackets and Balanced Brackets – Possible Second Attempt. I generated the post in 2016 and 2017 respectively. I guess, we will have a third version. Continue reading “Balance Brackets”

Print Immutable Linked List in Reverse

Hi gals and guys. Hope you are doing well during the COVID-19 pandemic. It seems that most of us are somewhat tired following the basic rules that reduce the spread of the coronavirus. By relaxing the rules in the past few months, the numbers of COVID-19 infections, in most cities worldwide, are going up. Note that the issue is the number of infections, not the number of deaths. Infected people may need hospital services. If the number of patients is larger than the capacity like it was when this thing started, then we have a problem. At this point in time, people with most infections per 1,000, is people in college age. Please follow the rules! We all benefit from it. Continue reading “Print Immutable Linked List in Reverse”

Stack Min

It is Monday evening. Yesterday, with the help of my wife we cleaned a spot in my home office and put together the 4K monitor and computer. Later I set up the computer. The monitor is impressive. The only this missing for today is to connect the Azure Kinect DK and start experimenting.

Today I solved (at least I think) the 3.2 question Stack Min from the book “Cracking the Coding Interview”. The question follows:  “How would you design a stack which, in addition to push and pop, has a function min which returns the minimum element. As I am reading the question I want to state that when I was solving the problem, I agreed with the imaginary interviewer that min function would return the min value. We could also have the solution return the minimum element (the actual node), but we decided that that was not the scope of the question. Continue reading “Stack Min”