Article tracker
54 leetcode articles in the last yearlast 6 months
Bookmarks
Quick lookup notes
Advice I’d Give to Anyone Starting Their LeetCode Journey (Including My Future Self)
I’ve learned that interview preparation isn’t about solving thousands of random problems. It’s about building the right habits, recognizing patterns, and learning how to think under pressure.
Understanding Big O Notation for LeetCode: The Complexity Cheat Sheet Every Beginner Needs
Big O notation measures the time complexity (or sometimes space complexity) of an algorithm. It doesn’t tell you exactly how many milliseconds your code takes—it tells you how the runtime grows as the input size (n) increases.
Think in Patterns, Not Solutions: A LeetCode Playbook
Goal: Don’t memorize solutions. Memorize patterns. Most LeetCode questions are variations of these.
Patterns
Problems solved by pattern
Journey log
LeetCode write-ups
230. Kth Smallest Element in a BST
A BST's inorder traversal visits nodes in ascending order. The kth node visited during inorder traversal is the kth smallest element. The recursive solution is concise and easy to understand. The iterative solution uses a stack to simulate recursion and is the standard interview approach.
LeetCode 98: Validate Binary Search Tree (Python)
Comparing a node with only its parent is not sufficient. Every node must satisfy constraints inherited from all its ancestors. Passing a valid (lower, upper) range during DFS elegantly enforces the BST rules. This is the standard interview solution and is both simple and optimal.
1448. Count Good Nodes in Binary Tree (LeetCode)
This is an excellent example of a DFS problem where the trick is not the traversal itself, but what information you carry along the path. By passing the maximum value seen so far, each node can determine independently whether it is "good," resulting in a simple and efficient O(n) solution.
199. Binary Tree Right Side View (LeetCode) – BFS Explained
Whenever a binary tree problem asks for something "per level", BFS should be one of your first thoughts. For the right side view: Traverse level by level. The last node of every level is visible from the right. Record it and continue.
LeetCode 235: Lowest Common Ancestor of a Binary Search Tree
Binary Search Trees (BSTs) are special because they allow us to make decisions without exploring every node. This problem is a great example of taking advantage of that property to find the Lowest Common Ancestor (LCA) in O(h)time instead of searching the entire tree.
572. Subtree of Another Tree – Explanation
A brute-force approach would compare subRoot against every node, which is exactly what this recursive solution does. Since each comparison uses the optimal Same Tree algorithm, this is the standard interview solution and is accepted by virtually every interviewer.
LeetCode 110: Balanced Binary Tree – Three DFS Solutions Explained
Whenever a tree problem asks you to determine something about a node based on information from its children, think post-order DFS. For this problem, every node needs: left subtree height, right subtree height, whether both subtrees are already balanced
Leetcode 104 : Maximum Depth of Binary Tree — Recursive DFS, BFS, and Iterative DFS
With recursive DFS, the answer for each node is:1 + the greater depth of its two subtrees With BFS, the answer is the number of levels processed. With iterative DFS, each node is stored together with its current depth.
226. Invert Binary Tree – Three Ways to Solve It (Recursive, DFS, and BFS)
Binary Tree problems are a staple in coding interviews, and Invert Binary Tree is one of the most famous ones. Despite its simplicity, this problem is an excellent exercise for understanding tree traversal and the differences between recursive DFS, iterative DFS, and BFS.
LeetCode 287: Find the Duplicate Number — Floyd’s Cycle Detection Explained
The duplicate creates a cycle because two indices eventually lead to the same node. Floyd’s Tortoise and Hare algorithm detects that cycle without modifying the array. Resetting one pointer to the start lets you find the cycle entrance, which is the duplicate number.
LeetCode 206: Reverse Linked List – A Simple Iterative Approach
Linked lists are one of the most fundamental data structures, and reversing a linked list is a classic interview question. Although the problem is straightforward, it tests your understanding of pointers and how nodes are connected.
LeetCode 4: Median of Two Sorted Arrays – From Brute Force to Binary Search
One of the most famous hard problems on LeetCode is Median of Two Sorted Arrays. At first glance, it looks straightforward—you just need the median of two sorted arrays. But the catch is that the required time complexity is O(log(m + n)), which rules out the obvious approach.
LeetCode 981: Time Based Key-Value Store Explained (Binary Search Solution)
The elegant part of this problem is recognizing that the timestamps are already sorted because of the problem constraint. The combination of: a hash map for fast key lookup, and binary search on the timestamp list gives an optimal solution
LeetCode 153: Find Minimum in Rotated Sorted Array – Binary Search Explained
Binary search isn’t just for finding an element in a sorted array. One of its most powerful applications is searching for a boundary or turning point. LeetCode 153: Find Minimum in Rotated Sorted Array is a perfect example of this pattern.
739. Daily Temperatures — Explanation
We need to return an array result, where result[i] tells us how many days we have to wait after day i to get a warmer temperature. The monotonic stack solution is more efficient because it keeps track of unresolved days and updates them as soon as a warmer temperature appears.
Leetcode 42: Trapping Rain Water: From Brute Force to Optimal Two Pointers
The Trapping Rain Water problem is an excellent example of how understanding the properties of a problem can lead to significant optimizations. The biggest takeaway is recognizing that the smaller of the two maximum boundaries determines the water level.
Leetcode 15: 3Sum – From Brute Force to Two Pointers
The key insight is realizing that after sorting the array, we don’t need three nested loops anymore. Instead: Fix one number., use two pointers to search for the other two, skip duplicates carefully and stop early once the fixed number becomes positive.
LeetCode 128: Longest Consecutive Sequence — Explanation
Given an integer array nums, return the length of the longest consecutive sequence that can be formed. The key trick is to only begin counting when we find the start of a sequence. This avoids repeated work and allows us to solve the problem in linear time.
Leetcode 36 : Valid Sudoku - Explanation
Sudoku is a classic 9×9 puzzle where each row, column, and 3×3 box must contain the digits 1 through 9 without repetition. In this problem, we are not asked to solve the Sudoku board. Instead, we only need to check whether the current board is valid.
Leetcode 1: Two Sum Explained: From Brute Force to an Optimal Hash Map Solution
The Two Sum problem is one of the most popular coding interview questions. Although it looks simple, it introduces several important concepts that appear repeatedly in algorithm design, such as brute force search, sorting with two pointers, and hash maps.
LeetCode 242: Valid Anagram – 3 Python Solutions Explained
Valid Anagram is a classic string problem that teaches different ways to compare the frequency of characters in two strings. While the problem is simple, it introduces an important concept you’ll use repeatedly in coding interviews: counting occurrences efficiently.
Solution: Leetcode 21 Solving the Merge Two Sorted Lists Problem in Python
You are given the heads of two sorted linked lists, list1 and list2. Merge the two lists into one sorted list. The list should be made by splicing together the nodes of the first two lists. Return the head of the merged linked list.
LeetCode 155: Min Stack – Constant Time Minimum Lookup
The key insight isn’t about finding the minimum quickly—it’s about remembering the minimum as the stack evolves. By maintaining a second stack that mirrors the main stack and stores the minimum value at every level, we eliminate the need to recompute the minimum after every pop().
Solution: Leetcode 682 Solving a Baseball Scoring Puzzle with Python
You are keeping the scores for a baseball game with a unique set of rules. At the beginning of the game, you start with an empty record. You're given a list of strings operations, where each element represents an operation to apply to the record.
Solution: Leetcode 1929 Solving the Array Concatenation Problem in Python
You are given an integer array nums of length n. The task is to create a new array ans of length 2n such that ans[i] == nums[i] and ans[i + n] == nums[i] for 0 <= i < n (0-indexed). In simpler terms, the array ans is formed by concatenating two copies of the array nums.
Solution: Leetcode 26 Removing Duplicates from Sorted Array in Python
The problem at hand is to remove duplicates from a sorted integer array nums in-place, such that each unique element appears only once. Additionally, we need to return the number of unique elements present in the modified array.
88. Merge Sorted Array – LeetCode Solution Explained Problem Link
You are given two integer arrays nums1 and nums2, sorted in non-decreasing order, and two integers m and n, representing the number of elements in nums1 and nums2 respectively. Merge nums1 and nums2 into a single array sorted in non-decreasing order.
