Design HashMap – Second approach

Today is Christmas Eve Day 2020 and we woke up with -3 F. In addition snow and wind started yesterday afternoon. Looks like a perfect day to stay in and roast a turkey.

As a matter of fact, my wife and I prepared the turkey early this morning and put it in the oven. The raw turkey came in at 24 lbs. It had giblets and a bag of liquid for basting. We disposed of those items. Next time we roast a turkey will get a smaller one (about 11 lbs.) and from a different brand (not Jennie-O). The breast of this turkey is not in proportion to the weight. Will see how the sandwiches on ciabatta bread turned out later this afternoon. Continue reading “Design HashMap – Second approach”

Binary Search in Java

It is Thursday and not much to report. My wife and I are planning on baking a couple things this weekend. Will update you on a couple recipes we are interested in making.

Earlier today I selected LeetCode 704 Binary Search. I was browsing the LeetCode site and have not implemented the binary search algorithm in this blog so here it is.

Given a sorted (in ascending order) integer array nums of n elements 
and a target value, 
write a function to search target in nums. 
If target exists, then return its index, otherwise return -1.

Note:

o You may assume that all elements in nums are unique.
o n will be in the range [1, 10000].
o The value of each element in nums will be in the range [-9999, 9999].

The array need to have numbers in sorted order. If the numbers are not sorted it is easy to figure out that it will not work. The opposite is true for a binary reach tree. If the input is sorted we will get an inefficient linked list with all the values. Continue reading “Binary Search in Java”

1-bit and 2-bit Characters

Today is Wednesday morning. It seems that the high temperature for the day will be 31F. Better than yesterday but my wife and I live in the Twin Cities of Minneapolis and St. Paul and winters are rather harsh in this part of the country.

This morning I decided to move from solving Facebook technical interview questions to Microsoft. I will try to solve a couple problems a day if time allows. Will see how it goes. My source will be LeetCode. At some point I might switch to HackerRank.

Without further ado, let’s get to the problem at hand. Continue reading “1-bit and 2-bit Characters”

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”

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”

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”

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 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”