Interval HashMap

A couple weeks ago, during a meeting, someone mentioned an interval hashmap. I decided to check if Java had a class implementing a version of an interval hashmap. As you can imagine, it does and is called NavigableMap.

In this post I explored some of the features available in the NavigableMap interface.

If interested, I would suggest to first take a look at the Interface NavigableMap<K, V> in the Oracle Java documentation which can be found here.

After reading the Oracle documentation and some articles in GeeksforGeeks and StackOverflow I decided to start experimenting. Continue reading “Interval HashMap”

LeetCode 681. Next Closest Time in Java

In this post we will solve LeetCode 681. Next Closest Time problem using the Java programming language, the VSCode IDE on a Windows computer. Please note that the computer platform and the IDE should make no difference. One of the simplest ways to solve the problem is to use the online IDE provided by LeetCode.

Given a time represented in the format "HH:MM", 
form the next closest time by reusing the current digits. 
There is no limit on how many times a digit can be reused.

You may assume the given input string is always valid. 
For example, "01:34", "12:09" are all valid. 
"1:34", "12:9" are all invalid.

Constraints:

* time.length == 5
* time is a valid time in the form "HH:MM".
o 0 <= HH < 24
o 0 <= MM < 60

Related Topics:

o String
o Enumeration

We are given a string with a time expressed in 24-hour format. By reusing the digits as many times as needed, we need to form the next closest time. Continue reading “LeetCode 681. Next Closest Time in Java”

LeetCode 223 Rectangle Area in Java

In this post we will solve LeetCode 223 Rectangle Area in Java.

Given the coordinates of two rectilinear rectangles in a 2D plane, 
return the total area covered by the two rectangles.

The first rectangle is defined by its bottom-left corner (ax1, ay1) and its top-right corner (ax2, ay2).

The second rectangle is defined by its bottom-left corner (bx1, by1) and its top-right corner (bx2, by2).

Constraints:

o -10^4 <= ax1, ay1, ax2, ay2, bx1, by1, bx2, by2 <= 10^4

Related Topics:

o Math
o Geometry

We are given the coordinates of two rectilinear rectangles in a 2D plane and are asked to return the total area covered by the two rectangles. Continue reading “LeetCode 223 Rectangle Area in Java”

LeetCode 445 Add Two Numbers II in Java

In this post we will solve the LeetCode 445 Add Two Numbers II problem using the Java programming language. We will generate two implementations of the function in question. The first will use two stacks while the second will reverse the singly linked list. When reversing linked lists we will implement an iterative and a recursive set of functions.

You are given two non-empty linked lists representing two non-negative integers. 
The most significant digit comes first and each of their nodes contains a single digit. 
Add the two numbers and return the sum as a linked list.

You may assume the two numbers do not contain any leading zero, except the number 0 itself.

Constraints:

o The number of nodes in each linked list is in the range [1, 100].
o 0 <= Node.val <= 9
o It is guaranteed that the list represents a number that does not have leading zeros.

Follow up:

o Could you solve it without reversing the input lists?

Related Topics:

o Linked List
o Math
o Stack

We are given two singly linked lists with digits representing two non-negative numbers. We need to return their sum in a singly linked list. If interested in this problem I suggest you visit LeetCode and get the current version of the problem. Sometimes the requirements are updated. Continue reading “LeetCode 445 Add Two Numbers II in Java”

LeetCode 1185 Day of the Week in Java

In this post we will attempt to solve the LeetCode 1185 Day of the Week problem.

Given a date, return the corresponding day of the week for that date.

The input is given as three integers representing the day, month and year respectively.

Return the answer as one of the following values {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}.

In a nutshell we are given a date in day, month, and year and we need to return a string that contains the name of the day. The problem is very easy to understand. Continue reading “LeetCode 1185 Day of the Week in Java”

Merge Sort Revisited

Good morning! Hope your day has started on the right note. Yesterday was quite hectic for me. Hopefully the day will go as smooth as possible. Continue reading “Merge Sort Revisited”

Direct Recursion

Good day software developers and software engineers. The forecast for today Thursday in the Twin Cities of Minneapolis and St. Paul calls for rain and thunderstorms. As usual the forecast changed at least a couple times in the past few days. Today the storm is forecasted for the evening hours. So far I have not heard thunder. I do not like to have my computers on during a thunderstorm. A couple times I have lost some equipment. Continue reading “Direct Recursion”

Fraudulent Activity Notification

Good day software developers and engineers. Hope your day is going well. The days are getting shorter and colder in the Twin Cities of Minneapolis and St. Paul.

As usual, my wife fixed lunch. It was quite good. Some type of meat stew. For desert we had `gypsy’s arm`. If interested in this dessert please read the article “Gypsy’s Arm Explained“. My wife has been making this desert since we were dating. At some point she used a single can of `dulce de leche`. In the past couple years she is been using two cans. That makes for a much better dessert. Please do not confuse `dulce de leche` with `tres leches cake`. They are completely different things. Continue reading “Fraudulent Activity Notification”

Memory Pools – Revisited

It is Friday morning. The day started with a thunderstorm and some rain. After breakfast the storms were done. Last Thursday afternoon we had powerful storms with lots of rain. Some roads in the area had about two inches of water during the storms. Cars on roads were splashing water all over. I did not hear about accidents. That was good news!

After my first 2-hour block I sat with my wife and chatted for a few minutes. We were discussing the fact that for most people their normal state does not reflect happiness. It is a shame because such state just builds on itself and continues to spiral downwards. We try to be approachable both at home and work. People like and appreciates such behavior. Continue reading “Memory Pools – Revisited”

Unique Binary Search Trees

It has been raining all day in the Twin Cities of Minneapolis and St. Paul. The good thing is that there has been little lightning. I was going to replace an old UPS that I am using to power my main computer in which I develop all the code for this blog, but it was not necessary. I will replace the UPS over the weekend. Continue reading “Unique Binary Search Trees”