Posts

Bfs Shortest Reach

Introduction

This hackerrank problem at a high level is pretty easy since it’s a straight forward BFS algorithm however the few differences in the problem statement led me to stumble to a coding solution.

  1. The input given is not helpful, we need to transform it in a more.
  2. The mismatch between …

Circular Tour

Introduction

I wanted to discuss this problem since it was one of those where intuitively the brute force solution was not too hard to find out but making it more efficient was. These ended up being one of those problems where the code to the solution and the intial way you interpret the problem …

Minimum Bribes

Introduction

When I was first solving this problem I was able to pass some of the test cases but was caught off guard when I would fail the following case.

[1,2,5,3,7,8,6,4]

This case is a valid case (it’s not considered chaotic) however you’ll notice that many bribes occurred in an a …

Flip Matrix Brute Force

Introduction

Warning: Code may not be 100% compilable but it should be close. I was making changes along the way so although at one point it passed the test cases it might not now.

In our previous posts we learned how to reverse rows and columns which we can use to solve Flip Matrix in a brute …

Reversing rows and cols …

Introduction

I want to cover the Flipping the Matrix problem in a non optimal way in order to practice a few fundamentals that I think are important. In this post we’ll cover nested loops and list comprehensions and in the next post we will cover backtracking and combinations.

List …

K Diff Pairs

Introduction

We’ll take a look at a problem similar to k-diff pairs in this post. Specifically we’ll focus on a pattern that appears every now and then where you can improve your time complexity by changing the way you think. These sorts of optimizations are important. Always start with …

Longest Increasing …

Intro

Stumbled into an amazing YouTube Channel that helped describe this pattern that appears in DP problems

1D DP Solution (Reconnecting the previous element index with the choice)

Using the direct prefix of the problem does not work

Multiple candidates are an issue

This problem lead me to realize …

Longest Increasing …

Introduction

Following some popular leetcode solutions (1)

Understanding the recursion through the choices we make

Take or Don’t Take

The way you can view the recursive solution is that should we :

  1. Choose to take the current element and include it into our set of longest increasing
  2. Choose not …

2D Matrix One Liner

Introduction

Python can be a powerful language since it allows you to acheive a lot through a few lines of code. The example we’re taking a look at in this post is how to create an M x N matrix.

dp = [[1]*n for i in range(m)]

We’ll break this into two parts:

  1. Sequence Repetition
  2. List …

Word Break II: Brute …

Intro

In the previous post we explored a more intuitive way to view the problem. In this post we’ll code the brute force algorithm and focus a little more on the time complexity details.

Recursion Intro

With recursion it’s all about the recursive leap of faith and thinking in a lazy …

Word Break = Choosing …

Intro

In this post we’ll go over the popular leetcode problem Word Break. This posts focuses more on how this problem can be viewed as choosing partitions. I belive that at a first glance it seems like there is no connection between the two so it is a neat discovery to make. In the editorial …

Monotonic Stack Ii

Peak and Valley View (Which history you want determines which form of monotonic stack/queue to use)

image

Monotonic Stack/Queue …

Goal

Introduces you mainly to the Monotonic Stack in an intuitive way with code snippets included. This post should help you understand when to start thinking of using a monotonic stack.

Introduction

In some problems like next greater element you see this pattern where one value can trump many …

Beware of blind …

Introduction

I ran into this problem for an initial assessment and found myself short on time. I was comfortable with a fairly similar problem in container with most water however wasn’t sure if the way I was “extending” the problem was correct. Unfortunately after finding the …

Choose Unchoose Pattern …

Recognizing the Pattern

In this part we’ll just focus on how to better recognize this pattern as well as variations in the code that show up.

Regular Power Set

Let’s say the set is:

A = {1, 2, 5}

To find the power set of A, we need to find all possible subsets of A. The power set of A …

Coin Change

Intuition

https://labuladong.gitbook.io/algo-en/iii.-algorithmic-thinking/detailsaboutbacktracking#permutation

The Problem

You are given an integer array coins representing coins of different denominations and an integer amount representing a total amount of money. Return the fewest number of coins …

Processing Tax (Graph …

Goal

The goal of this blog is to discuss graph traversal algorithms and give a little more intuition between the flow of the actual code. The blog assumes you are already familiar with Breadth First Search (BFS) and Depth First Search (DFS) algorithms. I would always forget when do you add a node to …

Countdown Pattern

Introduction

This pattern is pretty rare but it’s easy to spot once you recognize it. Let’s take a look at two problems that have this pattern. It does not improve your time or space complexity but it makes the overall approach to the code a litte simpler.

Koko Eating Bananas …

Reorganize String

Introduction

The patterns that you run into for this problem are pretty interesting which makes it slightly challenging to understand how to iterate through when you code up the solution. It’s a placement problem.

Transforming the input

In this case the input is not actually helpful and if …

Choose Unchoose Pattern …

Introduction

This is part two of my discussion on the choose unchoose pattern found in programming interview questions. This post will specifically focus on the loop aspect of the pattern. We will use the Combination Sub problem as the application to the concepts.

Understanding why a loop also works …

About

  Welcome to my page. How you got here I have no clue but I hope it can be of service to you in some way. My goal for this page is to discuss some concepts that I think are of value. Short and sweet posts that expand or introduce you to topics that I stumbled on. After some time I've learned to …

Stable Sort = Complex …

Introduction

Sometimes you learn the hard way in life. Con is that there was a potential cost. On the plus side you will likely not forget it. In today’s topic is brought to you by me taking twice as long to complete my interview assessment and potentially failing it for that reason. So the …

01 Matrix (BFS with …

Introduction

We’re taking a look at 01 Matrix on Leetcode today. The main motivation is to realize that when using BFS you can start with multiple sources instead of a single source. This just means that even though we usually start out with a “root” and do BFS from there, you can …

Insert Interval

Introduction

Today we’ll take a look at Insert Interval. The reason why I think this is a useful problem to learn is because it helps you approach these problems in such a way where the code is more intuitive. Essentially the reasoning behind this problem and others like it is that it is not …