One of the Leetcode problems that I worked on this week is called Maximum Subarray Sum. If you would like to try it yourself, you can find it here. Although this is a relatively simple problem, I learned something new about JavaScript in the process of solving it, which is always great. I’m going to do a brief walkthrough of the problem and my solution, and I hope that it helps anyone who may be stuck.

The Problem


Disclaimer: Radix sort will only work for sorting numbers. I’ll explain why later on!

Throughout my studies of data structures and algorithms over the last couple of months, I have learned several sorting algorithms. Most of them are fairly similar in the way that they sort data. They compare two pieces of data at once and put them into the right place based on that. Bubble sort, merge sort, selection sort, insertion sort, and quick sort all fall into this category, which are called “comparison” algorithms. While these are all useful algorithms to know, and each have specific situations that…


The most recent project that I worked on was building a version of the classic game Mastermind. For those of you who are not familiar, Mastermind is a code-breaking game. This article’s focus will be on the logic I wrote to check whether or not the code had successfully been broken.

In the traditional two-player version of Mastermind, one player creates a secret code of four characters(usually different colored balls) and arranges it on a part of the board that is not visible to the other player. The second player’s job is to crack the secret code, and they get…


Sliding window is an extremely common problem solving pattern in computer science. It is most frequently used on arrays or strings. The main principle behind it is to create a ‘window’ within your array or string, and then check if the data in that window satisfies the condition of your problem. It can also be used to compare values from different ‘windows’ in your data. For example, lets say you are given an array of integers, and are tasked with finding the three consecutive integers with the greatest sum. You can create a window that spans three indices, and a…


One of the most helpful problem solving patterns in computer science is known as the frequency counter pattern. Commonly used on arrays and strings, it is named frequency counter because when we use it, we create an object or set to store the elements in our string or array, along with how many times they occur in that string or array. More specifically, the element is usually a key in the object, and the value for that key is how many times that element is found.

When should this pattern be used?

Frequency counters are most frequently(pun intended) used to compare data in some way. Some…


Studying data structures, algorithms, and practicing interview questions are essential parts of preparing to land your first job as a software engineer. Throughout my job search so far, I have been putting time into these endeavors but have definitely spent more of my time working on projects. I much prefer building sites and applications to doing interview questions, and it is essential to growing as a developer. At the same time, practice problems also help sharpen my skills and will make me better at working on my projects, just not as directly. …


Hash tables are one of the most commonly used data structures in programming. While I consider myself to be extremely comfortable with using them in code that I write every day, up until this week I had never taken the time to consider how they actually work. In this article, I will be giving a brief overview of what hash tables are, hash functions, how to handle collisions, and the big O of hash tables. Many of the screenshots in this post are from this replit page that I made, where I constructed a hash table from scratch.

Overview

Hash tables…


Last week, I wrote about my first foray into Binary Heaps, which can be found here. Having knowledge of heaps is really helpful when learning priority queues, since the optimal(but not only) way to implement them is with a heap. In last weeks post, I also had a link to a repl I made showing how to construct a max heap in JavaScript(here), as well as some essential methods to implement. I have added a priority queue class in that same repl.

What are priority queues?

A priority queue is an abstract data structure. It is a lot like a normal queue, except each…


A heap of trash
A heap of trash

Up until this week, the only heaps I was familiar with were the heaps of trash that are a mainstay of NYC streets. Thankfully this week of studying data structures has shown me that not all heaps are hot garbage. In this article, I will be reviewing what I have learned so far about binary heaps as well as how to construct and interact with them. A lot of the images in this article are from my repl, where I constructed a Max Binary Heap and wrote a few class methods to make it functional. I also have some notes…


Another week into studying data structures and algorithms, I am learning about tree traversal. Last week, I wrote a blog about my introduction to binary search trees, which can be found here. That article is an overview of what trees are, and how to construct them with JavaScript classes. This article will expand that same class, which can be found here, to include some of the more common algorithms for tree traversal.

Tree traversal is a classic computer science problem. The idea is to visit every single node in the tree once, regardless of the shape or specific type of…

Liam Hanafee-Areces

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store