Recently I’ve got to solve a problem on LeetCode, and decided to write this article because, even though it was not extremely hard, the whole complexity was in the precomputation of some data. Let’s have a look:
A good meal is a meal that contains exactly two different food items with a sum of deliciousness equal to a power of two.
You can pick any two different foods to make a good meal.
I’ve recently come across one of the thousands of problems that can be solved with dynamic programming techniques. I remember that, when I was trying to get my head around this topic, one of the most frustrating aspects was the ever-green Fibonacci Numbers example. It was everywhere, but I had the impression that reading over and over the same stories about overlapping subproblems and optimal substructures, always with the same example and the same images in from of my eyes wasn’t really paying off the effort. …
In this article, we are going to study and solve the medium difficulty LeetCode challenge Stone Game VII. It’s a sort of extension of the previous Stone Game VI, already analyzed and solved in this previous article. Let’s get started with the problem description, the examples, the analysis of the problem, and eventually the code.
First off, let me ctrl-c ctrl-v the problem description:
Alice and Bob take turns playing a game, with Alice starting first.
nstones arranged in a row. On each player's turn, they can remove either the leftmost stone or the…
Throughout this article, we are going to be analyzing an interesting coding challenge that I’ve recently happened to solve. Those of you who love problem visualization as I do might end up being disappointed because this time I didn’t manage to come up with a satisfying visualization of the problem, however, I’ll try my best to run you through the thoughts that led me to the solution.
In this article, we will be going through the solution to a coding challenge that I’ve recently had the pleasure to solve taking one of the LeetCode contests. Other than the solution itself, I’ll be providing an easy visualization that hopefully will make everything really simple to grasp.
I’m not going to spend much time here, let me just copy-paste the description of this problem titled “Sum of Absolute Differences in a Sorted Array”
You are given an integer array
numssorted in non-decreasing order.
Build and return an integer array
resultwith the same length as…
Recently I’ve got to spend some hours thinking of a useful visualization for a problem whose key point is a pretty straightforward intuition. I am a stronger believer in visualization to help make a concept stick. That being said, I have got to be honest, am not sure if I pulled it off this time, but eventually came up with something that I liked. Let me know your thoughts.
You are given…
In this article, we will be solving and discussing the solution to one of the problems that I have recently got to work on. I reckon that it deserves some attention, not for its complexity, but because it requires the developer to do a little analysis and precomputation on the input data to pave the way for an easy solution.
I have recently come across this problem while brushing up my algorithmic skills by solving a coding contest on LeetCode. It is titled “Ways to Make a Fair Array” and the description states:
You are given an…
In this article, we are going to be discussing an algorithm that lends itself to visualization. We will get started from a concrete problem, a code challenge that I’ve recently got to solve, trying to figure out a general approach that can be reused in many other circumstances.
This is a medium difficulty LeetCode problem called “Split a String Into the Max Number of Unique Substrings”. The description is the following:
Given a string
s, return the maximum number of unique substrings that the given string can be split into.
You can split string
In this article, I’ll be trying to describe a rather common Dynamic Programming technique used to solve an interesting coding challenge taken from one of the contests that you can find on LeetCode.
As DP (Dynamic Programming) can be a tricky concept, sometimes hard to grasp, I’ve endeavored to produce some pictures which will help to get the point across.
You are the manager of a basketball team. For the…
In this article, we are going to analyze part of the fascinating Binary Tree world. The applications of this data structure are limitless, and even though it might be a bit scary at first, I promise that with the help of some pictures and visualizations, we will be getting acquainted with it, and hopefully learning something new.
As usual, I like to start from a practical problem, why not the coding challenge which got me to write this post? So let’s kick this off.