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
Island Detection in Binary Matrices Using Graph Traversal
Given a rectangular binary matrix representing a geographical map where character '1' indicates landmass and '0' represents water, the computational task is to enumerate distinct islands. An island forms when land cells connect horizontally or vertically; diagonal adjacency does not constitute valid connectivity. The grid periphery is assumed t ...
Posted on Sun, 28 Jun 2026 17:16:35 +0000 by wdsmith
Reversing Linked Lists and Rotating Arrays: Efficient Algorithm Solutions
Reversing a Linnked List
Problem: Given the head of a singly linked list, reverse the list and return the new head.
Approach: Iterative Node Reversal
To reverse a linked list iteratively, we can utilize three pointers: current, previous, and temporary. The current pointer traverses the list, while the previous pointer keeps track of the reverse ...
Posted on Sat, 27 Jun 2026 17:54:19 +0000 by El Ornitorrico
Finding the Longest Palindromic Substring: Three Algorithmic Approaches
Given a string s, the objective is to locate and return longest substring that reads the same forwards and backwards.
Examples
Input: s = "babad"
Output: "bab"
Note: "aba" is also a valid answer.
Input: s = "cbbd"
Output: "bb"
Input: s = "a"
Output: "a"
Input: s = "a ...
Posted on Sat, 27 Jun 2026 17:42:13 +0000 by Sul
Solving the Minimum Path Sum Problem with Dynamic Programming
Given a m x n grid filled with non-negative numbers, find a path from the top-left corner to the bottom-right corner wich minimizes the sum of all numbers along its path. You can only move either down or right at any point in time.
Approach: Dynamic Programming
This problem is a classic example of dynamic porgramming. The key is to build a solu ...
Posted on Fri, 26 Jun 2026 17:06:09 +0000 by soulmedia
Solving LeetCode Problems Using Greedy Strategies
1648. Sell Diminishing-Valued Colored Balls
The objective is to maximize profit when selling balls whose values decrease by 1 after each sale. The optimal approach is a greedy strategy where we always sell the currently most valuable balls available.
By sorting the inventory in descending order, we can visualize the stock as columns. We process ...
Posted on Fri, 26 Jun 2026 16:49:48 +0000 by keystroke
Binary Search Patterns: Solving Common LeetCode Array Problems
Binary search is a fundamental algorithm that efficiently locates target values in sorted arrays. This article explores several classic LeetCode problems that leverage binary search, along with related array manipulation techniques.
Problem 704: Binary Search
When performing binary search on a sorted array, the choice of boundary conditions sig ...
Posted on Wed, 24 Jun 2026 16:35:07 +0000 by Lefu