LeetCode 1504. Count Submatrices With All Ones in Java

In this post we will solve LeetCode 1504. Count Submatrices With All Ones problem using the Java programming language, the VSCode IDE on a Windows computer. My suggestion to you is that unless you have some special set of requirements, use the online IDE provided by LeetCode.

Given an m x n binary matrix mat, 
eturn the number of submatrices that have all ones.

Constraints:

o 1 <= m, n <= 150
o mat[i][j] is either 0 or 1.

Related Topics:

o Array
* Dynamic Programming
o Stack
o Matrix
o Monotonic Stack

In this problem we are provided a two dimensional matrix that only contains 1s and 0s. The dimensions are specified by `n` and `m`. Our mission if we wish to accept it, is to return the number of submatrices of 1s. Continue reading “LeetCode 1504. Count Submatrices With All Ones in Java”

Best Time to Buy and Sell Stock II

It is a relatively nice day in the Twin Cities of Minneapolis and St. Paul.

This weekend my wife and I will go to visit our younger son. His house is about three hours by car. It does not make sense to fly. It will take longer than driving when you consider the overhead at the airports.

I continue giving it a try to the process to solve dynamic problems using some simple steps as described in the paper Dynamic programming is simple by omgitspavel. Each time I give it a try I add additional guidance.

The main problem that I see with the approach is that one still has to read, understand and explore other methods before diving into dynamic programming. The problem we will be solving in this post can be resolved faster and better not using dynamic programming. Continue reading “Best Time to Buy and Sell Stock II”

Best Time to Buy and Sell Stock with Transaction Fee

Good morning! Hope you had a great weekend. The weekend was not too exiting for my wife and me. We did replenish our freezers for the next few months. I believe we have enough supplies to last us through a good part of spring 2022.

We decided to cook some ribs in the oven. We have done this several times, but due to the fact that my wife is not too fond of such delicacy we have not cooked them in about three years. I pulled the ribs from one of the freezers and put it in a refrigerator for three days. On Friday evening I took them out of the fridge and they were still partly frozen.

On Saturday morning after breakfast I rubbed some salt and pepper on the ribs. Like I mentioned, she is not too fond of ribs or BBQ sauce. I wanted to add some that we got at Trader Joe’s a couple weeks ago. I ended using the sauce on my dish. My wife used an Asian sauce which went very well with ribs. We also bought that sauce at Trader Joe’s.

I was going to set the oven at no more than 300F, but my wife suggested 325F to get them done faster. The ribs went in around 07:00 AM. After showering and getting dressed, I went down to my office for a 2-hour block.

Later that morning my wife and I sat down for a cup of triple espresso. We chatted and decided to get a couple items at a specialty grocery store in St. Paul. We turned off the oven and headed out. In retrospect, we should have removed the ribs from the oven. We had lunch around 01:00 PM and the ribs got a little dry for my taste. We had them with brown rice and black beans. We both enjoyed them, but once a year is enough. The taste is very unique like turkey. We have turkey on Thanksgiving Day and perhaps Christmas. I guess most people do the same in this part of the country.

On a separate note, I ran into the article Was Our Universe Created in a Laboratory? by Avi Loeb published on Scientific American on October 15, 2021. The article starts with the word “Opinion” which puts it into perspective.

I am not going to get into the implications of the ideas in the article. My parents taught me never to discuss religion, money or sex. Such subjects are very opinionated and it is hard to get a general consensus. That said; here we are talking about the article. The reason for me to bring it up is due to the fact that for the past three decades or more, when my wife and I talk in private, I have described to her the idea of multiple universes generated by beings more advanced than us. In such universes there are some actual beings and many artifacts. The idea behind is to study scenarios that in general fall outside our comprehension and interests.

I have to tell you that as soon as I read the article, I ran to my wife to tell her about it. We both thought it was very interesting.

In my thoughts and opinion, the article does not exclude a superior being that is above all levels. It just puts such being above the more advanced civilization(s) that at this point are able to generate universes.

I will try to contact the author of the article and let him know that I really enjoyed reading it. After an hour or so of sending my message to the author, I received a reply. Thanks. Continue reading “Best Time to Buy and Sell Stock with Transaction Fee”

Divisor Game

It is Thursday and the workweek is almost done. Continue to walk with my wife every morning unless it is raining. Today it was 75F and 75% relative humidity. The conditions were not the best, but we completed our walk. On my way back I watered the plants. It takes me less than 5 minutes.

The lawns in the neighborhood have patches of dried grass. Most lawns have sprinklers but between the heat and the lack of rain, I would venture to say that about 15% of the grass in most (never say all) laws is yellowish indicating it is very dry.

The saga with the presidential elections in Peru continues. Contrary to what the news from American sources (i.e., Reuters, The Guardian, and The New York Times) state, there has been massive fraud and it seems that the communist candidate will win using fraud. Have we seen this before? Continue reading “Divisor Game”

Count Construct – Tabulation

Earlier today I read an article commenting about how the high temperatures are rising all over the USA. In Arizona and Nevada the forecasted highs should be about 115F and 112F respectively. The average temperature for a human adult is around 98F. That is quite warm if you ask me.

Today in the suburb in the Twin Cities of Minneapolis and St. Paul where I reside, we woke up with 72F. At some point we might be getting some rain. The high is forecasted to be 91F and we are still in spring 2021.

My wife and I have breakfast and then head out for a walk. We like to get the workout in first thing in the morning. After returning home, I watered some plants that were replaced outside a week or so ago. I have been informed that I need to water them 3 to 4 days a week for a month or so until the plants adapt to their current location; so far, so good. We do need some rain. The lawns in our area are starting to show some brown spots. We can see and hear the sprinklers in the morning, but seems that laws need additional water. A few good down pours each month would take care of the brown spots. Based on NOAA’s forecast, it is going to be a dry and hot summer for most parts in the USA.

Yesterday I mentioned that I requested a callback from a Delta agent. Based on the information at hand, I was expecting the callback in about two hours. I did receive the call. At that time I had performed enough searches on the web that I had solved the issue before talking with the agent. All is well at this time. Continue reading “Count Construct – Tabulation”

Grid Traveler – Tabulation

It is another nice and hot spring day in the Twin Cities of Minneapolis and St. Paul. Yesterday after work my wife and I headed to the bank. On our way back I noticed that the temperature had gone up to 99F.

Earlier today after breakfast my wife and I went out on our daily walk. There were more people than usual. We stopped to talk with a neighbor that was also out and about. She likes to walk at a good pace. She was covered in sweat.

The forecasted temperatures for the next couple weeks will are in the mid 80s to the mid 90s. During lunch time the temperature went up to 93F. In general the high temperature for the day occurs around 05:00 PM.

A couple weeks ago we were talking with a couple of neighbors. They mentioned that some of our plants in the front yard were dead. Today during lunch the company that handles plants and lawns stopped by to remove and replace all the dead shrubs.

On a separate note, things are not going well with the vote counting process. There seems to be a lot of cheating going on. It seems that the candidate that represents communism and terrorism will get elected president. The economy has come to a standstill. The Peruvian currency is devaluating.

In addition the candidate from the left is instigating people to go after the upper and middle classes. Hope this things is resolved peacefully in the next few days. Continue reading “Grid Traveler – Tabulation”

Red John is back

It is another warm Tuesday morning in the Twin Cities of Minneapolis and St. Paul. When the COVID-19 pandemic started my wife and I stopped walking on a daily schedule. A couple weeks ago we started walking. Slowly we are trying to get to 10,000 steps a day. Currently we are around 6,500 steps. In addition after every 2-hour block of work I get on a stationary bike and pedal fast and furious for 5 minutes. I tend to get 4 to 5 short sessions per day. My wife decided to skip the bike. That said; we both are starting to feel the benefits of exercising once again. We love it!

On a separate note my best friend sent me a message that he was starting to test ProtonMail for personal and potentially commercial use. I replied that I have been experimenting with it on my defunct Pixel 4 cell phone. After it died with less than two years of use a couple weeks ago, I switched for the first time to an iPhone. I am still installing applications. Today I will install ProtonMail and will continue testing the service. About three months ago I mentioned ProtonMail on my post Largest Triple Products – Revisited. I like the encryption and the fact that they do not use or sell your personal information. Continue reading “Red John is back”

All Construct

It is Saturday morning in the Twin Cities of Minneapolis and St. Paul. According to the forecast today is going to be a scorcher. The temperature will rise to 97F. I live in a suburb of the Twin Cities. Typically the city of Minneapolis gets at least a couple more degrees higher.

Yesterday my wife and I went to the Mall of America which is located in the city of Bloomington. On our way back home the temperature was 102F.

Given the hot spell we are experiencing in this part of the country, this morning my wife and I had breakfast and headed out for a walk. When we got back I was perspiring. After a nice shower I headed down to my office to get in a 2-hour block of work.

Tomorrow Sunday presidential elections will be held in Peru. There are two candidates. One is an open communist and terrorist and the other is pro democracy. Hopefully the elections will favor the right. Politically and economically South America is slowly falling to communism and the economies of most (never generalize) are getting worse by the day. Will see what happens tomorrow during election day. Continue reading “All Construct”

Can Sum?

Today is a cold and dark day in the Twin Cities of Minneapolis and St. Paul. It has been raining all day. The forecast matched the day. Hopefully tomorrow it will be nicer.

Yesterday evening my wife and I were sitting in the living room watching YouTube videos. All was working as expected. At some point I decided to look for a video to watch so I picked up my phone that was sitting next to me on the couch. The phone was dead. I tried powering it up at no avail. I thought the battery might have discharged. Strange because when I picked it up from the wireless charger the phone was about 100% charged.

I tried pressing button sequences to restart the phone. That did not work.

I pulled my cell phone out of the OtterBox case. The phone looks like new. I decided not to open the actual phone thinking I might cause an additional problem. I put my phone back into the OtterBox case.

I then decided to put the phone to charge on a wireless charger. After half hour or so later I tried to power up the phone. It was not able to power up. I then tried with a regular plug-in charger. Half hour later the phone was still completely dead. Decided to take my Pixel 4 phone to T-Mobile and see if they can diagnose and hopefully fix the issue. We will find more about it today after work…

…Later in the day I took my cell phone to the T-Mobile store closest to home. They were able to rest the phone. All is back to normal. I did ask if T-Mobile would carry the Pixel 5 phone. Apparently they have no plans to do so. My wife and I might switch to Apple for the first time when our Pixel phones need to be replaced. Continue reading “Can Sum?”

Sam and Substrings

It is a sunny Tuesday in the Twin Cities of Minneapolis and St. Paul. The earlier forecast was calling for thunderstorms. I just check the revised forecast and it seems that we might have some rain after dark. That is good news because my wife and I are invited to our oldest son’s house today to have the next version of the burgers we had last Saturday as I commented on the Roads and Libraries post. Will let you know tomorrow how it goes.

As I mentioned in a previous post, a few weeks ago I had elective surgery performed on my left knee. All is going very well with the recovery process. So far most of the physical therapy sessions have been on Tuesdays and Thursdays towards the end of the day (04:30 PM or 05:00 PM). Today the session is at 01:30 PM. My wife changed our daily lunch schedule to accommodate it. We will be having lunch after therapy.

Yesterday we spoke over Skype with a couple friends of us that live in Peru. Things are not going well in Peru or Latin America in general. Seems that communism is creeping at alarming rates. In the next presidential elections to be held on June 06, 2021 there are two candidates. One candidate represents the right and the other the left. The left has mandated voters in different places to take a picture of their secret ballot to allow party representatives to verify that the votes are for the communist candidate. If voters refuse their lives would be in danger. Not much to say about a secret and fair election!

Of course the bottom line is always money. In this case some foreign nations will benefit by getting several mines at a much discounted price. It seems like a repeat of what transpired and is still going on in Venezuela. Such is life. Continue reading “Sam and Substrings”