In this article, we will be solving LeetCode’s Swapping Nodes in a Linked List in JavaScript. Here is an article I wrote on Linked Lists and goes through a LeetCode problem. Recap, a linked list is a linear collection of nodes where each node points to the next node. Each node has a value property and a next property which references the next node in the list. This is what makes linked lists a linear data structure. There is a sequence and an order to the list. To get to the end of the list, we must start at the…

In this article, we will be solving LeetCode’s Find Center of Star Graph in JavaScript. This article will be using what we have learned from my “Intro to Graphs” series.

Part 1 was the general introduction of what graphs are. In summary, a graph data structure is a finite set of vertices (nodes) and a set of edges that connect a pair of nodes. In graphs, there are no rules dictating the connection among the nodes. The edges can connect nodes no matter their placement.

Part 2 was learning about the two standard approaches of representing graphs, an adjacency matrix…

Hello all! This is part 3 of the series Intro to Graphs. Part 1 was the general introduction of what graphs are. In summary, a graph data structure is a finite set of vertices (nodes) and set of edges which connect a pair of nodes. In graphs, there are no rules dictating the connection among the nodes. The edges can connect nodes no matter their placement. Part 2 was learning about the two standard approaches of representing graphs, an adjacency matrix and an adjacency list. This article will be going over graph traversal.

Why do we need to know graph…

Hello all! This is part 2 of the series Intro to Graphs. If you missed part 1, the link is here and at the bottom of this article. Recap, a graph data structure is a finite set of vertices (nodes) and set of edges which connect a pair of nodes. In graphs, there are no rules dictating the connection among the nodes. The edges can connect nodes no matter their placement. In this article, we will go over representing graphs. The two standard approaches to representing graphs are an adjacency matrix and an adjacency list.

A graph data structure is a finite set of vertices (nodes) and set of edges which connect a pair of nodes. In graphs, there are no rules dictating the connection among the nodes. The edges can connect nodes no matter their placement.

Link to the problem is here and in the resources section.

We have a collection of stones, each stone has a positive integer weight.

Each turn, we choose the two **heaviest** stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:

- If x == y, both stones are totally destroyed;
- If x != y, the stone of weight x is totally destroyed, and the stone of weight y has new weight y-x.

At the end, there is at most 1 stone left. Return the weight of this…

This article will build upon my previous article on heaps. As a refresher, a heap is a special kind of binary tree that follows a set of rules. A heap can be a max heap which will have their biggest value as the root and the value of each parent node is always greater than its child nodes. Otherwise, it is a min heap which will have their smallest value as the root and the value of each parent node is always smaller than its child nodes. Heaps have no implied ordering between siblings.

Priority queue is one of the…

Welcome to heaps. Heaps have a binary search tree like structure. Each parent node has two children nodes that all stem from a root. Heaps can be ordered in two ways:

**Max Heap: **A max heap will have their biggest value as the root and the value of each parent node is always greater than its child nodes.

**Min Heap:** A min heap will have their smallest value as the root and the value of each parent node is always smaller than its child nodes.

Heaps have no implied ordering between siblings. The bigger one can be the left child…

I find the best way to follow up my last article on stacks, would be an article on queues. Queues and stacks are often talked about together because they are similar, even though their uses and implementations are different. I will go over the basic concept of queues, and just like my other articles, I will go over a LeetCode problem to show how they are used. The LeetCode problem: Number of Students Unable to Eat Lunch. The question sounds grim, but it is a good problem to show off how to use queues.

Just like a stack, a queue…

The next data structure on my list to explore are stacks. I find the best way to fully comprehend data structures such as stacks are to explain what they are and then walkthrough practice problems. I will give a brief overview of what a stack is then I will go over a stack problem that I have recently completed on LeetCode: Remove All Adjacent Duplicates In String. Let us first define what a stack is and then dive in.

I am writing this with an empty stomach, so I will use pancakes as an example. You decided to have your…

Flatiron School software engineering alum. Experienced in JavaScript, React.js, Ruby, and Ruby on Rails. https://www.linkedin.com/in/chandler-hanson/