Reverse Linked List

In this post I will reverse a linked list in Java. As I mentioned in a previous post, I am in the process of refreshing recursion using Java. In the next few days I will pick up a few more problems and post my approach.

In this post I will deal with 206. Reverse Linked List. If interested please take a look at the requirements for the problem and then give it a try before looking at solutions. Continue reading “Reverse Linked List”

Number of Recent Calls

It is an ugly rainy and stormy day in the Twin Cities of Minneapolis and St. Paul.  It seems like the storms will resume around 03:00 PM later today. In general I shutdown all my desktop computers when there are thunderstorms. I have a couple UPS units but I have also invested time installing software and configuring them exactly the way I like it. Do not wish to change disks or re install software.

Earlier today I opened the LeetCode web site and selected the problems icon. In the search box I entered the word “recursion”. Many problems were listed. I sorted them by difficulty Easy to Difficult. I then selected problem 933. Number of Recent Calls. Time permitting, decided to tackle three problems in the three categories in the next few days. Continue reading “Number of Recent Calls”

Longest Univalue Path

I have a childhood best friend which we both attended K-12 in the same sequence of schools. We used to hang out on weekends and in some occasions would go out with the family. After high school we both went in different directions. We lost track of each other while attending college. A few years went by and we reconnected. Since then we have visited in person and our spouses appear to have connected well.

Through the years we kept in touch about once a month via Skype. Since the COVID-19 pandemic started, we talk once a week, typically on Friday. We are both morning people so we set the call time between 06:00 AM and 07:00 AM. This morning around 05:00 AM I received a message via Gmail that he had some work appointments early morning. We skipped the call but will reconnect next week. Continue reading “Longest Univalue Path”

Lowest Common Ancestor of a Binary Tree

Things might be getting somewhat more complex with the COVID-19 pandemic that started in Wuhan, China. The CDC has been posting articles stating that individuals, who have recovered from COVID-19, may be prone to reinfection after three months. The theory of herd immunity, without a vaccine, goes out the door.

On a side note, people in the city of Wuhan, China have been celebrating that coronavirus is receding (there is no way to find out with data what is actually happening there) in their city with a massive water park party. The Chinese Communist Party does not seem to accept responsibility for the 800,000 deaths globally which they allowed to happen and are taking advantage of it in different ways. Continue reading “Lowest Common Ancestor of a Binary Tree”

Lowest Common Ancestor in Binary Search Tree

It is a beautiful sunny summer day in the Twin Cities of Minneapolis and St. Paul. The high temperature for today in the city I live is forecasted to be 83 F. I prefer high temperatures in the range of 75 F to 80 F, but 83 F will have to do.

Yesterday I spent a few hours in front of my computers. My wife left early with a friend to go walking and shopping. My wife got back shortly after 11:00 AM. We made some potatoes with veggies in the grill using a cast iron pan. We always add some pepper, salt and a splash of oil with a high smoke point (i.e., avocado or peanut). Continue reading “Lowest Common Ancestor in Binary Search Tree”

Greatest Common Denominator

Last weekend my wife and I visited our son and family who live in Madison, Wisconsin. They like to cook and bake like we do. When I was growing up, most summer days I would make ice cream. The techniques and ingredients were quite simple.

Over the weekend my son made ice cream. He did it using the ice cream bowl for the Kitchenaid mixer. It happens that we also have an ice cream bowl. When we got back, we decided to make some ice cream using the same recipe that our son had used. We searched for our ice cream bowl which we have not used in years, but were not able to find it. We decided to use a regular bowl and the standard 6-wire whip attachment. Continue reading “Greatest Common Denominator”

Sum Two

This weekend my wife and I spent it in Madison, Wisconsin visiting our son and family. We left Friday after work and returned Sunday afternoon. The drive is between 3.5 and 4.0 hours depending on traffic. Given that we are in the middle of the COVID-19 pandemic, we were amazed at how much traffic we encountered.

Last Friday morning I took a look into a couple problems but did not have time to write the associated posts. I will do if I have some time in the near future. Note that I have already addressed a similar problem in my post Sum of Two earlier this year.

In this post I will cover a problem I searched for on the web. This problem comes in different flavors. I found the one on LeetCode so I decided to take a stab at it. Continue reading “Sum Two”

Single Element in a Sorted Array

Ventured into LeetCode and randomly selected the Single Element in a Sorted Array challenge. The requirements are very straight forward. Make sure you pay attention to the following Note: Your solution should run in O(log n) time and O(1) space. Continue reading “Single Element in a Sorted Array”

Valid Anagram

sample_anagramIt seems like anagrams are becoming quite popular in challenges. What is an anagram? The edited definition from Wikipedia follows:

“An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once. Any word or phrase that exactly reproduces the letters in another order is an anagram”. Continue reading “Valid Anagram”

Fraction Recurring Decimal

recurring_decimalsFor the past few months I had been working attempting to solve a challenge per day on HackerRank. I like that site. A couple weeks ago I was introduced to LeetCode. Challenges seem to be more intense and requirements seem to be vaguer. Knowing this, one needs to think and plan the approach / algorithm with greater care and expect to fail unit tests that one would not think off. I just finished a challenge and decided to post in this blog my approach to solving it. Continue reading “Fraction Recurring Decimal”