In this post we will solve the LeetCode 75. Sort Colors problem using the Java programming language and the VSCode IDE on a Windows computer.
Given an array nums with n objects colored red, white, or blue,
sort them in-place so that objects of the same color are adjacent,
with the colors in the order red, white, and blue.
We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
You must solve this problem without using the library's sort function.
o n == nums.length
o 1 <= n <= 300
o nums[i] is 0, 1, or 2.
We are given an integer array with values 0, 1, and 2 which represent colors red, white and blue respectively. We must solve the problem without the use of any library sort function. That makes sense because we would only have to sort the input array and return. Continue reading “LeetCode 75. Sort Colors in Java”
Good morning. I received a comment from Dmytro regarding the post Slow Sum suggesting the use of a priority queue instead of a stream. I appreciate the comment and suggestion. Continue reading “Slow Sum – Revisited”
Good day! I am approaching the end of my workday. My wife is in the kitchen preparing chocolate frosting for a chocolate cake she baked this morning. We were going to have a piece after lunch, but she was busy and did not get to the frosting.
Yesterday evening my wife and I watched the film No Time To Die which is the last James Bond movie with Daniel Craig. I am a 007 fan. Growing up I read all the novels by Ian Fleming who created the James Bond character. I have watched most of the James Bond films on opening night. This time I decided to wait for the film to be streamed from home.
Of course, there were a few books by Ian Fleming but there are much more films. In other words, most of the films are not based on the original books.
The last two films with Daniel Craig are Spectre and No Time To Die. I did not like Spectre at all. In my rankings it was the worst James Bond film at the time. After watching the new release, I can say that I did not like it either. I would rank it a small notch above the previous movie.
I have not much to say about Daniel Craig. As an actor he can help the delivery of the script, but that is it. If the story and script are not good, the film will follow. Daniel Craig has grown too old to play the 007 role. This is why No Time To Die was the last James Bond film for him.
The original character of James Bond was not represented in this film. The film was slow and his feelings were out of character. The movie was about 2.75 hours in length. To be honest, towards the end I was checking my watch to estimate how much of the movie was left.
There is a film named Knives Out with Daniel Craig and one of the Bond girls Ana de Armas. My wife and I have watched that film a few times. The plot and delivery by most actors is right on. The same cannot be said about No Time to Die.
If you are a fan of James Bond as I am, you must watch the film and then make up your own mind. The taste in people regarding films is hard to quantify. Many times we watch a movie highly rated and it turns out to be a disaster. Not too many times have we experienced the opposite.
On a side note, I was not able to finish this post yesterday. Will complete it right now. Continue reading “Values From List of Lists”
Happy Monday! Hope your day and week has started on the right note. With travel opening in Europe many are making plans and some are already travelling to Europe. It seems that most countries are eager and hopefully able to receive visitors in a safe manner.
Spoke with my youngest son this morning. He was heading to his office. Since the pandemic started he has been working from home like most people in the world has including me. Since the pandemic appears to be under control in many countries, including the USA, schedules are quickly changing and most people will be full time at the office at their place of work. Some companies will allow more flexibility than before with schedules allowing employees to work one or two days from home. Keep in mind that most studies have determined that face contact and casual meetings are associated with more productivity. Interesting fact, because most of us thought that chatting by the water cooler was a complete waste of time! Continue reading “Find K Pairs With Smallest Sum”
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”
!!! UPDATE UPDATE UPDATE !!!
I received a comment indicating an issue with the largestValues() function. The issue has been corrected. The code has been updated. Thanks for noting the issue.
Good morning! It is 04:15 AM and it is a relatively warm day. Last evening before going to bed I decided to hopefully get up a little earlier than usual. I have a permanent alarm on my phone for 06:00 AM. I use it as a fail-safe in case I do not naturally wake up before. Today I wanted to get this post done and take a look at a test I left running overnight. My wife has a doctor’s appointment early today and it is a 45 minute drive from home. She has to fast so I will follow suit. We should be leaving home around 06:45 AM.
On a separate note, I visited the ProtonMail web site. As we all know there are companies that offer free email services. They have redefined what the word free means. The cost is quite heavy regarding your privacy. In the past couple weeks I have been reading about email services. My wife and I are contemplating on opening accounts on a service in the near future. When that happens, you will see a new email address at the bottom of the posts. Continue reading “Largest Triple Products – Revisited”
Good morning. It is Sunday again. I woke up around 05:00 AM and the outside temperature was -17 F. We are finally experiencing cold winter days in the Twin Cities of Minneapolis and St. Paul. An added bonus for football fans is that today is Super Bowl LV. My wife and I are not sports fans. We like to bike and walk and occasionally scuba dive. Up to a couple years ago we would watch the half time show. We so not watch TV any more. Perhaps we will find the half time show on YouTube. Continue reading “Sort the Matrix Diagonally 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”
Tomorrow we should be able to learn about the possible fraud in the 2020 United States presidential election. Hopefully the discussions and events will be peaceful from both sides. It will be interesting to learn what went on and how is it going to be addressed.
Yesterday evening for the first time my wife and I watched a president Trump rally. This one was in an airport in Georgia. Interesting facts were presented. What called my attention was a comment made by the president regarding how some election officials use what was labeled as “intent by the voter” to decide if the ballot was for Biden or Trump. The officials inspect the ballot and they decide on what was the “intent” of the voter was, and they assign the vote to the “intended” candidate. WHAT??? If the voter filled in the slot for Biden, then the vote goes to Biden, if the slot for Trump was filled in, then the vote goes to Trump. Finally if both slots were left empty, the vote does not count. THIS IS THE BEGINING AND END OF THE STORY. There is NO INTENT. A seven year old understand this. Try explaining the rules to your kid and they will understand there is NO NEED to determine THE INTENT OF THE VOTER! Continue reading “Magical Candy Bars in Java”
Once again it is Friday during the COVID-19 pandemic. Not much to say due to the fact that outside work not much is changing. So far the COVID-19 vaccine development programs appear to be moving forward. Earlier this week UK started vaccinating people in nursing homes.
One of the sons of my best friend was married last year and moved to the UK. His wife and he had a baby boy about three months ago. My friend’s son, his spouse and newborn arrived earlier today for a month long visit. Hope they have a great time. Hopefully a month from now with the help of vaccines things will be getting better all over the world. Continue reading “Largest Triple Products”