Merge K Sorted Arrays

Good morning! It is once again Saturday morning during the COVID-19 pandemic. Today is March 13, 2021 and the sun is shining in the Twin Cities of Minneapolis and St. Paul. The forecast calls for the temperature to get up to 58F. For this time of the year it is welcomed. Tomorrow it will be a little cooler and daylight savings time starts at 02:00 AM when the clocks spring forward to 03:00 AM. Tomorrow we lose one hour.

A week or so ago I was talking with an engineer about merging a set of sorted arrays. I also generated the post Merge Sorted Array which probably motivated the exchange. If you take a look at the last post, the idea was to merge two sorted arrays. The obvious next step is to consider multiple sorted arrays of the same or different lengths. In that post we considered two approaches. In the first one we add all the elements from both arrays into a priority queue. We then populate the result array with the elements being removed from the priority queue. Continue reading “Merge K Sorted Arrays”

Merge Sorted Array

Good morning!  Hope your day has started on the right note. The high temperature in the Twin Cities of Minneapolis and St. Paul is forecasted to be about ten degrees less than yesterday. BTW, yesterday the temperature went up to 61F which is the highest this year so far. My wife and I were planning on grilling yesterday but one thing and the other and I ended having BBQ Chicken Teriyaki from Trader Joe’s. Tasty but I prefer my wife cooking (just making points).

It seems that COVID-19 vaccinations are starting to pick up Minnesota. We are behind other states but the expectations are high. We need to hit herd immunity as soon as possible. It seems that masks and social distancing will be a good idea for people with or without the vaccine for the near future until there is enough data to understand if we will need periodic vaccine boosters or not. Continue reading “Merge Sorted Array”

Union Find Java

It is Monday morning. Lots of work associated things for the day so this post will be direct to the point.

As I have previously mentioned, I am in the process of reading Algorithms in C Third Edition Parts 1 – 4 by Robert Sedgewick. I finished the first chapter and wanted to experiment with the content in the book. Yesterday I got VSCode on my machine to compile and execute. I thought I was ready to use the IDE in C. It seems that when I created a new project something did not work. I am currently using the MinGW compiler with VSCode. The issue might be associated with it. I decided that over the next weekend I will remove MinGW and will switch to the Microsoft C/C++ compiler. I do a considerable amount of work using Visual Studio Enterprise 2019 IDE. Have been using Visual Studio for a couple decades and I like it. VSCode is quite similar but yet different. Continue reading “Union Find Java”

Dot Product of Two Sparse Vectors in Java

It is Thursday and for a while it was snowing. We received a couple inches of fresh snow. Will see what the weather brings us this weekend. I believe Sunday is going to be the coldest day of this winter so far. We might hit -20F. That said; it appears that the weather forecast changes multiple times a day.

Today my wife was not at home for lunch. I prepare toasts with avocado. Put a dab of butter on a couple slices of ciabatta bread, place them on a cooking sheet and into the oven (set at 400F) they went for about seven minutes. While that was going on, I took out from the freezer a Butter Chicken with Basmati rice tray from Trader Joe’s. As soon as the toast was done I swapped the tray with the chicken. The instructions called for 25 minutes so I consumed the toast with avocado and went back to my office. Continue reading “Dot Product of Two Sparse Vectors in Java”

Shuffle an Array in Java

I have mentioned in recent posts that this year the temperature in the Twin Cities of Minneapolis and St. Paul has not dropped down to 0F yet. Well, that is changing this Sunday. It seems that the high temperature for the day will be -6F and the low -20F. The good news is that according to the forecast, the temperature will increase rapidly in the following days.

Last weekend I spend several hours on work stuff. Hopefully the following weekend will be a normal one. Not sure if my wife and I will be venturing out on the forecasted cold. Continue reading “Shuffle an Array in Java”

Shuffle the Array

This morning talking with one of my sons on Skype, I mentioned an article which I rewetted titled “China’s push to control Americans’ health care future”. My wife and I used to watch 60 Minutes every Sunday evening. About a couple years ago we stopped watching TV. It appeared to us that there was not much to watch. I liked the article. I agree with the points presented. To me the best part is the moneys offered to several states in the USA for a Chinese company to be allowed to offer COVID-19 services. My question is:  Where are the funds coming from? Stop for a moment and think about it… OK, now let’s move to a different subject.

Then the pandemic came. With it we started watching more content from Amazon Prime, Netflix and YouTube. In the past year it seems that two or three times Netflix has increased the price for their base tier by $1 each time. Yesterday I read the article “Why I’m canceling Netflix in 2021” which provides some reasons why you should be dropping Netflix. My wife and I seem to always watch YouTube and in addition Netflix or Amazon Prime. In these days we are favoring movies from Amazon Prime. They seem to have a larger and better selection and the service is part of Amazon Prime. Continue reading “Shuffle the Array”

Contains Duplicate

Good day! It is Thursday morning and it is a typical gloomy and cold winter day in the Twin Cities of Minneapolis and St. Paul. The good thing is that is Thursday. One more day to go to and we can start enjoying the weekend. For most of us the weekend will be 2-days long. It is different from the past two weekends in which most people enjoyed 3 or 4 days off work.

Due to COVID-19 my wife and I just leave home for grocery shopping and healthcare appoints when needed. The good thing is that vaccination has started in the USA and hopefully in a few more months most of us will be vaccinated and can start getting back to normal. We all will see what happens. Continue reading “Contains Duplicate”

Revenue Milestones in Java

Good day ladies and gentlemen. Today is Wednesday January 06, 2021. The claims of electoral fraud in the 2020 presidential elections in the USA continue to be brought up. One way or the other January 20 is about two weeks away. If the claims do not pan out then on that day we will have a new president be sworn in. We will be able to read news without political opinions.

Earlier today my wife fixed a delicious chicken dish with a white sauce with lemon and capers. She served it with rice, baked potatoes and beats. For desert we had chocolate ice cream followed by a triple espresso. That marked the middle of my day. In the afternoon I finished two additional 2-hour blocks. Continue reading “Revenue Milestones in Java”

Continuous Subarray Sum

Tomorrow is Thanksgiving Day 2020. My wife finished preparing three containers with cheesy potatoes casserole. She has been making this dish as far as I can remember. Due to the ingredients we tend to have it once or twice a day. I will provide the recipe and some pictures on tomorrows post. If I am not able to solve a problem and generate a post, will generate a post as soon as possible.

We are still in the midst of the COVID-19 pandemic. About two million people around the world have die of complications related to the novel coronavirus. My wife and I have some friends’ originally from Vietnam. We learned today that one of them is in the hospital and the other barely making it at home. One of my wife’s brothers has been diagnosed with COVID-19. He, his wife and two kids are in quarantine at home. Our best wishes and our thoughts go out to them for a quick and safe recovery. Continue reading “Continuous Subarray Sum”

Is Permutation

Let’s define the requirements for this algorithm. We are given two sets of integers. The idea is to check if the sets are permutations of each other. If they are, return YES; otherwise return NO.

First let’s make sure we agree with the definition of permutation. For the sets to be permutations we must have the same number of elements in both sets. Each set must have the same counts for each entry. For example if the sets are:

1 2 3 4 5 6

6 5 4 3 2 1

Then we would return YES. Both sets have the same length (six in this case) the numbers are the same on both sets, and the count of each number matches (one in this case).

7 6 5 0 9 7

7 6 1 0 9 7

Given that 5 is in the first set, but not in the second and 1 is in the second, but not in the first, these are not permutations of each other so we would return NO. Continue reading “Is Permutation”