Dynamic Programming Approaches for Palindrome String Problems
Counting Palindromic Substrings
This section addresses the problem of counting all palindromic substrings within a given string, similar to LeetCode problem 647.
Problem Description
Given a string s, determine and return the total count of palindromic substrings. A substring is a contiguous sequence of charcaters. A palindromic string reads the ...
Posted on Tue, 14 Jul 2026 16:19:33 +0000 by mdgalib
Understanding Recursion Termination Conditions for Binary Tree Path Problems
LeetCode 257: Binary Tree All Paths
Termination Condition Considerations
The statement if (root == nullptr) return; serves multiple critical purposes in recursive tree algorithms:
Primary Function Guard
When placed in the main function provided by LeetCode, this check handles the empty tree case. If an empty tree is passed to the main function, ...
Posted on Sun, 12 Jul 2026 16:49:45 +0000 by knickerlas
LeetCode Daily Problems: Binary Tree Traversals and Construction
590. N-ary Tree Postorder Traversal
Approach: Right-to-left, then root-to-left. Use a stack with a visited set to track processed nodes.
class Node:
def __init__(self, val=None, children=None):
self.val = val
self.children = children
def postorder(root):
if not root:
return []
stack = [root]
result = []
...
Posted on Thu, 09 Jul 2026 16:38:30 +0000 by balacay
Trapping Rain Water: Efficient Algorithmic Solutions
The Trapping Rain Water problem, as featured on LeetCode 42, asks you to calculate the total amount of water that can be trapped after raining, given an elevation map represented by an array of non-negative integers. Each element in the array represents the height of a bar with a width of 1. Water can be trapped between bars of higher elevation ...
Posted on Thu, 09 Jul 2026 16:13:37 +0000 by ohenewa
Essential LeetCode Problems with Optimized Solutions
Two Sum
Use a hash map to store each number’s index. For every element, check if the complement (target - current) exists in the map.
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:
seen = {}
for idx, val in enumerate(nums):
complement = target - val
if complement in se ...
Posted on Wed, 08 Jul 2026 17:19:04 +0000 by xeidor
Linked List Problem Solving: Swapping Nodes, Removing by Index, Finding Intersections, and Detecting Cycles
Swapping Adjacent Nodes in a Linked ListSwapping nodes in pairs requires careful pointer manipulation to maintain the integrity of the list structure. The core idea involves processing two nodes at a time, reversing their connection order while preserving links to neighboring nodes.A dummy header node simplifies edge cases by providing a consis ...
Posted on Mon, 06 Jul 2026 17:19:41 +0000 by pug
LeetCode Problem 160: Intersection of Linked Lists
Intersection of Linked Lists
Problem Link
LeetCode 160
Problem Statement
Given the heads of two singly linked lists, headA and headB, return the node at which the two lists intesrect. If there is no intersection, return nullptr.
The linked lists must retain their original structure after the function returns. You are not allowed to modify th ...
Posted on Sun, 05 Jul 2026 16:14:54 +0000 by bobthebullet990
Adding Two Numbers Represented as Linked Lists
Problem Description
You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order, and each node contains a single digit. Add the two numbers and return the sum as a linked list.
You may assume the two numbers do not contain any leading zero, except the number 0 itself.
Examples
Example ...
Posted on Fri, 03 Jul 2026 16:12:18 +0000 by persepha
Essential Algorithms for Coding Interviews: Merging Arrays, Linked Lists, and Tree Operations
Arrays and Strings
Merging Sorted Arrays
Naive Merge and Sort
class Solution {
public:
void combineArrays(vector<int>& arr1, int m, vector<int>& arr2, int n) {
for(int i = 0; i < n; ++i) {
arr1[m + i] = arr2[i];
}
sort(arr1.begin(), arr1.end());
}
};
Two-Pointer Forward Merg ...
Posted on Wed, 01 Jul 2026 18:08:43 +0000 by byronwells
Dynamic Programming Problem Solutions
Unique Substrings in Wraparound String
Given a string p, find the number of unique non-empty substrings of p that are also substrings of the infinite wraparound string "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz...". The infinite string repeats the alphabet sequence cyclically.
DP Solution: We'll use a DP array where dp[i] r ...
Posted on Mon, 29 Jun 2026 17:55:59 +0000 by eashton123