Maximum Subarray Sum – Kadane’s Algorithm

A day or two ago I was browsing Reddit.com and saw a question regarding finding the maximum sum of a sub array given an array of integers. I decided to do some exploration on the Kadane’s algorithm. I tried a couple brute force implementations. I then went for an implementation using the algorithm.

Maximum Subarray Sum

Given an integer arry nums, find the contiguous subarray (containing 
at least one number) which has the largest sum and return its sum.

The problem definition is quite simple. Implementing a brute force is not too bad but it is quite slow. After a couple implementations we will use Kadane’s algorithm in the third approach. Continue reading “Maximum Subarray Sum – Kadane’s Algorithm”

Validate Binary Search Tree – Revisited

Hope you enjoyed Thanksgiving Day 2020. My wife and I did even though it was just the two of use for late lunch. We prepared our usual menu with some minor twists. The menu was a young turkey (we usually cook a 20+ lbs bird) which came in at around 11 lbs. with potatoes casserole and meat stuffing (we not prepare the popular / traditional bread based kind). For desert we had monkey bread which we got from one of our neighbors. We had a little more than we should, so we decided to skip our after lunch espresso.

For the turkey, we added some spices, a little garlic clove, some butter and apple vinegar. We inserted a thermometer and cook it to 175F. We then took it out of the oven and let it rest. Typically the temperature rises north of 180F. Since the turkey weighted 11 lbs., the temperature only went up to 178F. Continue reading “Validate Binary Search Tree – Revisited”

Construct Binary Search Tree from Pre Order Traversal

It is Thanksgiving Week 2020 and we do not have a winner in the 2020 Presidential Elections yet. The amount of fraud in this year’s elections has been unprecedented. My comment has nothing to do with politics. It is just based on common sense for individuals 12 years of age and older. I have friends and relatives living in different parts of the world. Their confidence and respect in the USA is almost (never generalize) gone.

On multiple occasions and referring to different topics, I have mentioned in this blog a technique used when people want to understand the positions of each other. First both argue on behalf of their own positions. Then, and this is the key of the technique, they switch positions and argue in favor of the opposite position. It is amazing what you can learn about different ideas when you use this technique. The reason for this tends to be based on facts and logic. Continue reading “Construct Binary Search Tree from Pre Order Traversal”

First Web Application – Node.js

Hope you are having a nice day. Today is Tuesday. Unless I am mistaken, it has been three weeks since Election Day and as far as I know the results for the presidential election are still up in the air. Hopefully we will find out the results in the next few days.

Next week is Thanksgiving Day. My wife and I were planning on having very few people over, but after further deliberations, we decided that we will skip and celebrate Thanksgiving 2021 with family and friends. Based on what is going on with COVID-19, it seems that a few vaccines will be made available early next year. By November 2021 we expect that most things would be back to normal; that is, the new normal. Continue reading “First Web Application – Node.js”

Dates in Java

Today I woke up around 05:00 AM. Later this morning my wife has a lab appointment at 08:15 AM. I decided to get up, cancel my 06:00 AM alarm, and set a new alarm for 07:15 AM. That should give us ample time to get ready and drive to the appointment. Will have breakfast when we get back because she needs to fast for the blood test.

Not sure what is going on with the Presidential Election 2020 results. As I have mentioned in a previous post, the entire process is open to fraud. Do not understand how in the USA we do not use a voter ID card. In addition we should have a secure system in which voters go to their designated polling sites and vote electronically. A paper receipt can be used by voters to make sure the ballot is counted and has not been tampered with. Election Day should be the only day one can vote. If you miss it because it is not important to you, so you can wait four years and plan accordingly. Continue reading “Dates in Java”

Path with Minimum Effort – Java

I have been busy with work, reading and experimenting. So far it has been an interesting and rewarding workweek. That said, I am glad that tomorrow is Friday. Due to the COVID-19 pandemic my wife and I do not have big plans for the weekend with the exception of going out for groceries. I assume that you might be in a similar situation.

I decided to tackle LeetCode problem 1631 Path With Minimum Effort. Sometimes I go for the best approach I can came up with. In this case I kind of stopped before implementing it. My first approach timed out as expected. We will discuss the details. My second approach was accepted with a reasonable time. I still want to get one more pass on it but I just do not have time to get that done now. Continue reading “Path with Minimum Effort – Java”

Number of Islands – Java

Last evening before going to bed, I left a window in the kitchen opened just a crack. The temperature was forecasted to drop down to 37F, so I hopped it was going to be fine.

A few minutes past midnight I woke up. It felt somewhat chilly. I closed the window and checked the temperature in the upper level zone. It was at 68F which is at what we keep it during the winter months. I turned on the heat in the zone and went back to bed. During the rest of the night I heard the furnace kick in a couple times.

During breakfast my wife asked if windows were closed and the furnace was on. I told her about my midnight adventure. We agreed on leaving windows closed from now on until next spring. The system at home has an air exchange unit so it makes sense to keep the windows closed and the temperature at 68F. Continue reading “Number of Islands – Java”

Merge Two Binary Trees – Java

It is Monday morning. I got up earlier to finish the code and this post. Hope to be done before 06:00 AM. Today is my wife’s birthday. She is an evening person. Every morning I get up, fix breakfast, and then wake her up.

This year due to the COVID-19 pandemic (thanks China) we have not planned a celebration. Dates tend to shift by a day on non-leap years. Yesterday I received a message with Google photos that we took on yesterday’s date several years ago. Last year for her birthday we were with some family, friends in Rome, Italy. In the evening we all had a nice dinner and walked to the Fontana di Trevi and tossed three coins. That was a nice way to close the day. We like Italy and have been there many times. Perhaps next year things will be back to the new normal and will be able to celebrate once again in Rome. Continue reading “Merge Two Binary Trees – Java”

Maximum Depth of a Binary Tree

Good morning. Hope your day has started on the right note. A couple weeks ago, the extended weather forecast for the Twin Cities of Minneapolis and St. Paul had the high temperatures in the low 60’s and 70’s. This week we have experienced high temperatures in the mid 80’s. It seems that with the power of the cloud, large models that make use of AI, and tons of data, accuracy predicting the weather is still out of our reach.

I have a lifetime friend. Our friendship started in elementary school. Now with the COVID-19 (or Chinese flu) pandemic we connect using Skype on Friday at 07:00 AM. By 08:00 AM we both start or work day. Continue reading “Maximum Depth of a Binary Tree”

All Possible Full Binary Trees

Labor Day weekend 2020 is here. The temperatures in the Twin Cities of Minneapolis and St. Paul are getting lower. Given COVID-19, the Minnesota State Fair has been postponed this year. My wife and I are not fair goers. We have been there twice. Our oldest son, who lives in this area, tends to go at least once a year.

Yesterday my wife and I grilled a whole chicken and some steak. There were chicken leftovers for the week. Not sure what we will grill for lunch today. Today the high temperature will be in the lower 80’s. It should be a great day to grill. Continue reading “All Possible Full Binary Trees”