Sliding Window Technique and Spiral Matrix Generation
Minimum Size Subarray Sum
Given an array of positive integers nums and a positive integer target, find the minimal length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists, return 0.
Examples:
Input: target = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: The subarray [4,3] has the minimal lengt ...
Posted on Tue, 16 Jun 2026 17:11:50 +0000 by kusarigama
Mastering Linked List Techniques: Pairwise Swapping, Nth Node Removal, Intersection, and Cycle Detection
Problem: 24. Swap Nodes in Pairs
To swap two adjacent nodes, we need a pointer standing just before the pair. A dummy sentinel node placed before the head simplifies edge cases. The traversal pointer curr starts at the sentinel. Swapping involves rerouting next pointers in three steps while preserving references that might be lost.
The loop con ...
Posted on Tue, 02 Jun 2026 17:52:23 +0000 by deurwaarder
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
Efficient Array Algorithms: Two Pointers, Sliding Windows, and Matrix Simulation
Squares of a Sorted Array (LeetCode 977)
The challenge in squaring a sorted array that contaisn negative numbers is that the largest squares can appear at both ends of the array. While a naive solution involves squaring every element and then sorting the array in $O(n \log n)$ time, a more efficient $O(n)$ approach utilizes the two-pointer tech ...
Posted on Wed, 20 May 2026 06:33:31 +0000 by jskywalker
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