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”

Validate Binary Search Tree

It is a gloomy day in the Twin Cities of Minneapolis and St. Paul. The good thing is that we have about two days until Thanksgiving Day 2020. This year we are cooking an 11 lbs. turkey. Typically my wife and I make an 18+ lbs. bird. Not only that but we are dropping half of it at our granddaughters place. On Thanksgiving Day we will be connecting with family via Jitsi and Skype. Continue reading “Validate Binary Search Tree”

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”

Maximum Length of a Concatenated String with Unique Characters

Hello and hope you are doing well. Today the temperature went up to 51F in the Twin Cities of Minneapolis and St. Paul. I did not get a chance to go out. Hopefully we will experience a mild winter this year.

Sorry but it is the middle of the week (hump day) and I do not have much to tell you. Time appears to be passing quite fast. Many cities in the country are upping COVID-19 restrictions. It is going to be an interesting Thanksgiving Day coming up in about a week. My wife and I will be preparing a meal. Will take some to our family and on our way back will get on-line (Jitsi or Skype) and will enjoy the meal. Continue reading “Maximum Length of a Concatenated String with Unique Characters”

Simple and Second Web Servers in Node.js

I am about to call it a day. It is dark and cold (25 F) in the Twin Cities of Minneapolis and St. Paul. I am in my office attempting to finish this post while my wife is upstairs in the living room wrapped in a blanket. Tomorrow morning we will wake up to a balmy 12 F. What else can I say?

I am reading and experimenting with the content of the book “Get Programming with Node.js” by Jonathan Wexler. I am currently on page 55. Expect to be done with towards the end of next month. At that time I will switch to experiment with Deno. Then I will move on to generate and post a first pass of a storage server. It should be a lot of fun. Continue reading “Simple and Second Web Servers in Node.js”

Java Functional Programming – 1 of n

It is not a nice day in the Twin Cities of Minneapolis and St. Paul. It has been raining and snowing on and off all day. I assume the roads are somewhat slippery. The good thing is that we do not have to go anywhere this evening.

One of my goals is to continue learning and experimenting with Java. Experience has taught me that at work one tends to use a limited feature set of the programming language(s) you use. This is why on my own time I like to learn different programming languages and different features so when I design and develop software, I can be quite productive.

We all know that not all languages have the same syntax or features, but with time, most object oriented languages tend to add similar features (not to say the same) with a different name and syntax. That is why I also like to solve problems that require algorithms. Once you have the idea, it does not take too much to implement the algorithm in a different language. This seems to be the trend while developing microservices. The idea is to use the best language for a task. Continue reading “Java Functional Programming – 1 of n”

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”

Angle Between Hands of a Clock – Java

It is Tuesday November 03, 2020 and it is Election Day. As it is customary my wife and I got up at 06:00 AM. I prepared our usual breakfast (yogurt, mixed fruits, homemade granola and bananas). We have been preparing the same breakfast for a decade or so.

After breakfast, we both got ready and headed to our designated polling location. There were two lines. Both were moving at a reasonable rate. Once we got our ballots we filled them and inserted in the counting machine. We were at the site for about 15 minutes. All went as expected. Continue reading “Angle Between Hands of a Clock – Java”

Binary Search Tree to Greater Sum Tree – Java

Hello there. It is another Sunday morning during the COVID-19 pandemic. The current temperature in the Twin Cities of Minneapolis and St. Paul is about 30F and is sunny. As soon as I finish with this post my wife and I will stop by Target to get some sundries.

Yesterday my wife and I met my older son at Costco in Minneapolis. We get together every other weekend at Costco to do groceries. My wife and I got a 35 lbs. of beef chuck cut. Once we got home we cut smaller manageable portions, put them in bags and placed them in the freezer. We left one portion out. We cut it into smaller pieces, cut some potatoes, onions, garlic and carrots. Put them in a tray in a 550 degree oven for 10 minutes. The beef browned quite nicely. We then put the items in a pressure cook with some water and left them cooking for 1 ½ hours. We served them in on a thin base of very hot brown rice. I had two large servings. It was delicious. Continue reading “Binary Search Tree to Greater Sum Tree – Java”