Two-Pointer Techniques for Array Manipulation Algorithms
In-Place Element Removal
When tasked with filtering out specific values from an array in-place, allocating additional memory is often restricted. The two-pointer method provides an elegant solution by separating the reading and writing processes.
Strategy: Read and Write Pointers
We initialize two distinct indices: a write_idx to track the posi ...
Posted on Mon, 21 Sep 2026 16:38:55 +0000 by jacobelias
Essential Binary-Tree Algorithms and Their Implementations
In-Order Traversal
Recursive
List<Integer> inorder(TreeNode node) {
List<Integer> out = new ArrayList<>();
walk(node, out);
return out;
}
void walk(TreeNode cur, List<Integer> acc) {
if (cur == null) return;
walk(cur.left, acc);
acc.add(cur.val);
walk(cur.right, acc);
}
Iterative (Single Sta ...
Posted on Mon, 21 Sep 2026 16:25:53 +0000 by otterbield
Binary Search on Rotated Sorted Arrays
Let's explore 4 problems related to searching in rotated sorted arrays:
LeetCode 33: Search in Rotated Sorted Array
LeetCode 81: Search in Rotated Sorted Array II
LeetCode 153: Find Minimum in Rotated Sorted Array
LeetCode 154: Find Minimum in Rotated Sorted Array II
These can be categorized into three groups:
33, 81: Searching for a specifi ...
Posted on Sun, 20 Sep 2026 16:37:14 +0000 by frost
Exploring Greedy Algorithms: Theory and Implementation
Fundamentals of Greedy Algorithms
The core principle of a greedy algorithm is to make the locally optimal choice at each stage with the hope that these local choices will lead to a globally optimal solution. For instance, when counting currency, taking the largest denomination possible at each step ensures the minimum number of notes.
Unlike d ...
Posted on Fri, 18 Sep 2026 16:40:41 +0000 by fallen_angel21
Grouping Anagrams Using Sorted Strings as HashMap Keys
---------------🎈🎈 LeetCode Problem 49: Group Anagrams 🎈🎈-------------------
In Java, arrays cannot be used directly as keys in a HashMap because their hashCode() method does not reflect the actual content. It is therefore recommended to use immutable objects such as strings as keys.
Approach 1: Use a Sorted String as the Key
⭐️ Since two ...
Posted on Fri, 18 Sep 2026 16:20:45 +0000 by ckwall
LeetCode - Partition Equal Subset Sum
Given a non-empty array nums containing only positive integers, determine whether the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.
Example 1:
<strong>Input:</strong> nums = [1,5,11,5]
<strong>Output:</strong> true
<strong>Explanation:</strong> The array can ...
Posted on Fri, 18 Sep 2026 16:15:47 +0000 by verycleanteeth
Essential Greedy Algorithm Concepts and Classic Problem Solutions
Core Idea of Greedy Algorithms
The essence of a greedy strategy is to build a globally optimal solution by repeatedly making locally optimal choices. The typical workflow involves:
Breaking the problem into smaller subproblems.
Determining a suitable greedy criterion.
Obtaining the best posssible choice for each subproblem.
Aggregating these l ...
Posted on Thu, 17 Sep 2026 16:15:36 +0000 by lancet2003
Dynamic Programming: String Deletion and Edit Distance Problems
Delete Operation for Two Strings
Problem Statement Given two strings word1 and word2, determine the minimum number of steps required to make both strings identical, where each step allows you to delete exactly one character from either string.
Solution Approach This problem can be efficiently solved using dynamic programming. The key insight ...
Posted on Wed, 16 Sep 2026 16:15:54 +0000 by storyteller
Maximum Values in Sliding Windows via Monotonic Deques
Given an integer array nums and an integer k, a sliding window of size k traverses the array from left to right. Only the k numbers within the window are visible at any step, and the window shifts right by one position after each move. The task is to return the maximum element inside the window for every valid posiiton.
Example 1
Input: nums = ...
Posted on Mon, 14 Sep 2026 16:45:15 +0000 by itarun
Essential Data Structures and Algorithmic Patterns for Technical Interviews
Hash Table Fundamentals
The std::unordered_map and std::unordered_set are critical for O(1) average time complexity lookups. When using unordered_map<int, int>, map.find(key) returns an iterator to the entry if present, or map.end() if not. Similarly, unordered_set provides find() and count() methods to verify existence.
Array Deduplicati ...
Posted on Sun, 13 Sep 2026 16:56:13 +0000 by fatfrank