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 …
The Nature of BST nodes …
Characteristics of the problem
- You can’t start out with the root (lowest common ancestor)
- This is really a traversal problem
- 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 …
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:
- Choose unchoose pattern
- Leetcode Combinations Problem https://leetcode.com/problems/combinations/description
- Backtracking
Context
This pattern is often just given as a part of a template …
Intro
Introduction
TODO