Posts

01 Matrix (Solving DP by …

Trouble

Even if you traverse the node wouldn’t you need to traverse the node for every node. For each node we’d need to determine the distance by traversing it? Multiple traversals are costly

A Dynamic Programming solution comes into play. Ask your neighbor what is the distance to 0 from …

Work Smarter not Harder …

Introduction

After some time working on Leetcode you start to realize trends in the problem. One category that I have recognized is one where the “elegant” solution uses simple logic to narrow out work.

Brute Force

Create a sliding window with the size of minSize. One of the rules that …

Balanced Tree

Validate Binary Search Tree

Relate to LCA BST

The Nature of BST nodes …

Characteristics of the problem

  1. You can’t start out with the root (lowest common ancestor)
  2. This is really a traversal problem
  3. Each node has a range of values that it could contain which is from [min(leftSubtree), max(rightSubtree)].
    • Understanding this range means we know the possible children …

TODO

Intuitive Proof for …

Introduction

I found a few resources that I think did a decent job at explaining bits and pieces but not the full thing. This is also a tool for me to think things through as I go through the proof.

Leetcode solution with useful insights
Math stackexchange with useful insights
Neetcode’s …

Useful Code for Matrices

https://leetcode.com/problems/valid-sudoku/description/

How to iterate through chunks

When solving the following problem you also need to solve it for multiple subproblems. Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules:

Each …

Spiral Matrix

Discovery Stage

Understanding the return condition

Although it’s always important to do determine what problem you’re trying to solve is; it’s especially crucial in the beginning process of leetcode. Mainly due to the reason you don’t want to solve a problem that is harder …

Leetcode 91: Decode Ways …

Why I like this problem

https://leetcode.com/problems/decode-ways/
A lot of the canonical recursive problems you start out with have really simple code. Things that come to mind are https://leetcode.com/problems/fibonacci-number/, https://leetcode.com/problems/climbing-stairs/ and …

Quarrel With Dynamic …

DP is an Art

Snapshot is clear, global is not

An issue I ran into with developing an intuition with dp is that in some cases the immediete solution is obvious yet I had a nagging sense of how could it be right long term. To explain my issue I’ll go through a leetcode problem. …

Choose Unchoose Pattern …

Pre Requisites

This post won’t elaborate on the following topics since there is already many great ones:

Context

This pattern is often just given as a part of a template …

Intro

Introduction

TODO