Finding the Entry Point of a Linked List Cycle Using Floyd's Algorithm
Problem DescriptionGiven the head of a linked list, determine the node where a cycle begins. If no cycle exists, return null. The cycle is identified when a node can be reached again by continuously following the next pointer. The solution must not modify the original linked list.Algorithm ExplanationFloyd's Cycle Detection Algorithm, also know ...
Posted on Mon, 18 May 2026 06:09:36 +0000 by jordy
Java Algorithm Practice: Squares of Sorted Arrays, Minimum Size Subarray Sum, and Spiral Matrix II
977. Squares of a Sorted Array
Problem Link on LeetCode
Approach: Two Pointers Technique Since the array may contain negative numbers, we use two pointers to compare the squares of the elements from both ends. The left pointer starts at the beginning of the array, and the right pointer starts at the end. The larger square is placed at the curre ...
Posted on Thu, 14 May 2026 22:08:44 +0000 by cmanhatton
Common Linked List Algorithm Problems and Solutions
Node Class Definition
The following ListNode class serves as the foundation for all examples in this article:
import java.util.Arrays;
public class ListNode {
int data;
ListNode next = null;
public ListNode(int data) {
this.data = data;
}
public String toString(ListNode node) {
int[] values = new int[calcu ...
Posted on Thu, 14 May 2026 11:08:20 +0000 by duclet
Optimal Subsequence Deletion for Monotonic Targets: CodeForces 1334F
In this problem, we are given an array $a$ of length $n$ and a target array $b$ of length $m$. Each element $a_i$ has an associated deletion cost $p_i$. We need to find the minimum cost to transform $a$ in to $b$ using a specific "strange function" $f(a)$, or determine if it is impossible.
Condition Analysis
The function $f(a)$ genera ...
Posted on Tue, 12 May 2026 14:29:23 +0000 by dr bung
Classic Linked List Techniques: Pairwise Swapping, Backward Deletion, Intersection, and Cycle Entry Detection
Swappnig Adjacent Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return the head pointer. Only pointer manipulation is allowed; nodde values must remain unchanged.
A sentinel node simplifies boundary handling. Maintain a prev pointer positioned immediately before each pair. In every iteration, identify the first node, the ...
Posted on Sat, 09 May 2026 16:12:35 +0000 by sonofsam
Linked List Algorithm Implementations
Swapping Nodes in PairsApproach: Using a dummy head nodeLogic: Create a dummy head node to simplify the swapping process. Use a current pointer that moves forward two steps at a time. The loop continues as long as there are at least two more nodes to swap.Implementation:/**
* Definition for singly-linked list.
* struct ListNode {
* int v ...
Posted on Sat, 09 May 2026 03:30:26 +0000 by drorshem
Minimizing Interval Length Difference for Common Intersection Using Segment Trees
Given $n$ closed intervals on a number line, the objective is to select exactly $m$ intervals such that they share at least one common coordinate point. The cost of a selection is defined as the difference between the maximum length and the minimum length among the chosen intervals. The length of an interval $[l, r]$ is calculated as $r - l$. T ...
Posted on Fri, 08 May 2026 22:58:06 +0000 by Jak-S
Linked List Problems: Swap Pairs, Remove Nth From End, Intersection, and Cycle Detection
24. Swap Nodes in Pairs
Problem: Swap adjacent nodes in a linked list pairwise, returnnig the new head. Do not modify node values—only rewire nodes.
Approaches:
Iterative: Use a dummy head to track the previous node. Adjust pointers for each pair.
Recursive: Swap the first two nodes, then recurce on the reamining list.
class Solution:
...
Posted on Fri, 08 May 2026 00:18:32 +0000 by dey.souvik007