## Insertion Sort – Revisited

Insertion Sort implements an algorithm similar to ordering a hand of cards in ascending order. The algorithm is O(n^2) execution and typically is useful when sorting a rather small number of elements.

Several years ago (November 03, 2016) I generated the post Insertion Sort in this blog. The code snippets do not look nice. It seems that the tool I was using to format source code is no longer working as expected. Continue reading “Insertion Sort – Revisited”

## 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 84. Largest Rectangle in Histogram in Java

In this post we will solve LeetCode 84. Largest Rectangle in Histogram problem using the Java programming language and the VSCode IDE on a Windows computer.

Given an array of integers heights representing the histogram's bar height where the width of each bar is 1,
return the area of the largest rectangle in the histogram.

Constraints:

o 1 <= heights.length <= 10^5
o 0 <= heights[i] <= 10^4

Related Topics:
* Array
o Stack
* Monotonic Stack

We are given an array representing a histogram. The width of each bar holding a value is 1 unit. We are asked to return the area of the largest rectangle in the histogram. Continue reading “LeetCode 84. Largest Rectangle in Histogram in Java”

## LeetCode 1302. Deepest Leaves Sum in Java

In this post we will solve the LeetCode 1302. Deepest Leaves Sum problem using the Java programming language with the VSCode IDE on a Windows computer.

Given the root of a binary tree,
return the sum of values of its deepest leaves.

Constraints:

o The number of nodes in the tree is in the range [1, 10^4].
o 1 <= Node.val <= 100

Related Topics:

o Tree
o Depth-First Search
o Binary Tree

We are given a binary tree and we need to return the sum of the values of all deepest leaves. Continue reading “LeetCode 1302. Deepest Leaves Sum 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.

o Could you solve it without reversing the input lists?

Related Topics:

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”

## Stone Wall

Good day! Hope all is well in your neck of the woods. My wife left lunch in the oven and ran to the dentist office. She left the oven on. Not sure when I should shut it down. I think I will do it right now before the food gets burned. When she gets back we can turn on the oven back if needed.

OK, the oven is off. It is 01:00 PM. I am starving. Hope my wife returns shortly so we can have lunch. Continue reading “Stone Wall”

## MaxProductOfThree

Good morning! Hope your day has started on the right note.

In this post we will attempt to solve the Codility_ problem MaxProductOfThree using the Java programming language and the VSCode IDE on a Windows platform. We will not be using the online IDE provided by Codility_ since we will write the code on a separate computer. Continue reading “MaxProductOfThree”

## Reverse Words in a String III

Good day! Hope your day has started on the right note. Earlier today I participated in a video call using Zoom. I have avoided using Zoom due to security issues. Today I had to install it in order to participate in the call. It seems that the look and feel has improved considerably. Will read more about security issues in the past few months. One way or the other, after the call ended, I removed the application from my Windows computer.

I was chatting with a software engineer and the idea of replacing the garbage collector in Java came up. In general you would replace it if it is not keeping up with the task (i.e., too many requests when processing IoT calls). I am aware and have done it using C and C++. After completing this post I will spend an hour researching more on this subject. Continue reading “Reverse Words in a String III”

## Flatten a Multilevel Doubly Linked List

Good morning software developers and software engineers! Hope your day has started on the right note. Every morning, weather allowing for it, my wife and I have breakfast and go for a brisk walk. Today was no exception. Before 08:00 AM I have watered plants in the yard including a rosemary bush that we planted a week ago or so, showered, shaved, got dressed and started my work day. It is amazing how well you feed during the day once you have exercised, no matter how short or long.

Last week I read the article (let me see if I can find it in my Twitter account @john_canessa … found it) Cybersecurity bills gain new urgency after rash of attacks. It seems that both political parties, Democrats and Republicans are pushing a bill that will help our country against cyber attacks. In the past few months we have seen hundreds if not thousands of attacks, some to disable our government, companies and organizations or to ask for ransom. One of the proposed ideas is to force targets to disclose in a short period of time (24 hours or so) any cyber breach they have experienced. This will allow the government and other organizations to take action as needed to prevent the same type of attacks. In my opinion there should be some type of penalty for the bad actors in an attempt to curb their proliferation (transparency and accountability). Will see what happens with the bill and its implementation! Continue reading “Flatten a Multilevel Doubly Linked List”

## Gray Code

Yesterday it rained all day and night. Today when my wife and I woke up the outside temperature was 58F. Not that cold but it called for long sleeve t-shirts.

Last night rain did wonders for lawns. They are starting to look very green and lush. It seems that on Friday we might get some additional rain which is good for farmers and lawns.

Over the long weekend my wife and I prepared bruschettas. Coming from Italian parents, while growing up, I consumed my fair share of this antipasto.

In the past few years we have prepared them now and then. This past long weekend my wife and I decided to prepare different flavored bruschettas before lunch. They were simple to prepare and we had them with beer, red and white wine and Prosecco. Prosecco is the champagne of Italy as Cava is the champagne of Spain. The change in names was required after the French patented the name champagne only to be used for sparkling wine produced in some parts of France.

You can use any bread, slice it and toast it until it gets a light golden brown color. We prefer to use Ciabatta or Focaccia bread. Yes, my family comes from the Ligurian region in Italy.

We get packages of four Ciabatta rolls at Trader Joe’s. We keep them in the fridge. With a serrated knife we slice them diagonally with a thickness of ½ inch or so. We put them in a convection oven at 450F until they turn light golden brown. My mouth is starting to water thinking about how good these things are.

We also get at Trader Joe’s a variety of jars of tapenades. They are reasonably priced and the flavors are incredible.

Once the bread is done, we pull it out of the oven and moved the pieces to a serving platter. We get a couple jars of tapenade and two spoons that are used to get about a full spoon of tapenade on to a piece of bread. Open your mouth wide and place the bruschetta in it. If you try them, please leave me a comment. I think they taste extremely good!!! Continue reading “Gray Code”