Singly Linked List Reversal: Iterative and Recursive Solutions for LeetCode 206
Problem Statement
Given the head of a singly linked list, reverse the order of all nodes in the list and return the head of the reversed list.
Sample Input 1:
head = [1,2,3,4,5]
Sample Output 1:
[5,4,3,2,1]
Sample Input 2:
head = [1,2]
Sample Output 2:
[2,1]
Sample Input 3:
head = []
Sample Output 3:
[]
Constraints:
The number of nodes i ...
Posted on Sun, 31 May 2026 19:45:10 +0000 by cowboysdude
Linked List Algorithms from Code Thinking Record
Table of Contents
Introduction
Remove Linked List Elements (LeetCode--203)
Design Linked List (LeetCode--707)
Reverse Linked List (LeetCode--206)
Swap Nodes in Pairs (LeetCode--24)
Remove Nth Node From End of List (LeetCode--19)
Linked List Cycle II (LeetCode--142)
Introduction
Following the Code Thinking Record series, this article explores ...
Posted on Sun, 31 May 2026 19:14:58 +0000 by gingerboy101
Dynamic Programming: Solving Multi-State Problems
The Massage Therapist Scheduling Problem
Problem link: https://leetcode.cn/problems/the-masseuse-lcci/
A renowned massage therapist receives a continuous stream of appointment requests. Each appointment can be accepted or declined. Due to the need for rest periods between sessions, she cannot accept consecutive appointments. Given a sequence of ...
Posted on Sat, 30 May 2026 19:39:23 +0000 by stelthius
Dynamic Programming: Core Concepts and Algorithmic Implementations
Understanding Dynamic Programming
Dynamic programming (DP) is an optimization technique used to solve complex problems by breaking them into simpler subproblems. It stores the results of subproblems to avoid redundant computations, thereby improving efficiency. This article explores fundamental DP concepts and implementations through various al ...
Posted on Wed, 20 May 2026 00:48:10 +0000 by saint959
Fundamentals of the 0-1 Knapsack Problem and Partition Equal Subset Sum Solution
Core Principles of the 0-1 Knapsack Problem
The 0-1 Knapsack Problem serves as the foundation for various packing challenges. Given a set of items with specific weights and values, the objective is to maximize value while not exceeding a given capacity constraint. Each item can be included at most once.
Dynamic Programming Solution
We use a DP ...
Posted on Sun, 17 May 2026 06:53:50 +0000 by stickynote427
Solving Longest Valid Parentheses, Trapping Rain Water, and Wildcard Matching Problems
Longest Valid Parentheses
Given a string containing only '(' and ')', find the length of the longest valid (well-formed and contiguous) parentheses substring.
Dynamic Programming Solution
Define dp[i] as the length of the longest valid parentheses ending at position i. To each character at index i:
If s[i] is '(', set dp[i] = 0
If s[i] is ')', ...
Posted on Sat, 16 May 2026 08:12:44 +0000 by mitchell_1078
LeetCode 62: Unique Paths (Dynamic Programming, Combinatorics)
Problem Description
A robot is located at the top - left corner of an m x n grid (marked 'Start'). The robot can only move either down or right at any point. The goal is to reach the bottom - right corner (marked 'Finish'). We need to determine the number of unique paths possible.
Examples
Example 1:
Input: rows = 3, cols = 7
Output: 28
Exampl ...
Posted on Sat, 16 May 2026 05:47:43 +0000 by ansarka
LeetCode Problem Solutions: Sliding Window and Hash Table Techniques
Trpaping Rain Water Problem
Given an array representing elevation maps, this problem calculates how much water can be trapped between bars after raining.
vector<int> leftMax(n, 0);
vector<int> rightMax(n, 0);
if (n == 0) return 0;
leftMax[0] = height[0];
rightMax[n-1] = height[n-1];
for (int i = 1; i < n; ++i) {
leftMax[i] = ...
Posted on Fri, 15 May 2026 23:00:45 +0000 by jck
Ambiguous Coordinate Generation Algorithm
Problem Analysis
Given a string containing only digits within parentheses, the task is to generate all valid coordinate pairs that could have produced the original string when punctuation was removed. The coordinates must adhere to specific formatting rules: no leading or trailing zeros in decimal components, and decimal points must be preceded ...
Posted on Wed, 13 May 2026 14:32:49 +0000 by nevynev
Hash Table Applications in LeetCode Top Interview Questions
Hash table are primarily used to store key-value mappings, enabling efficient lookups. They exemplify a time-space tradeoff—using extra memory to reduce time complexity for search operations.
Two Sum
Input: nums = [2,7,11,15], target = 9
Output: [0,1]
Because nums[0] + nums[1] == 9.
A naive approach uses nested loops, resulting in O(n²) time co ...
Posted on Wed, 13 May 2026 11:27:49 +0000 by vipul73