String Concatenation Matching Using Double Scissors Technique

Problem Statement Given two strings s and t, and an integer k, determine if it's possible to extract two non-overlapping substrings of length k from s such that when concatenated, the resulting string contians t as a contiguous substring. Approach Problem Analysis: The solution involves checking if t can be formed by combining parts of two no ...

Posted on Thu, 06 Aug 2026 16:48:27 +0000 by magic003

Mastering KMP for String Matching: Implementing strStr and Detecting Repeated Substrings

Implementing strStr() with the KMP Algorithm Given a haystack string and a needle string, locate the index of the first occurrence of the needle. The Knuth–Morris–Pratt (KMP) algorithm avoids redundant comparisons by precomputing a prefix table (often called the LPS – Longest Proper Prefix which is also Suffix – array). First, construct the LPS ...

Posted on Wed, 22 Jul 2026 16:42:34 +0000 by wizhippo

Remove Duplicates from Sorted Array

Problem Description Given a non-strictly increasing (sorted with possible duplicates) integer aray nums, remove the duplicates in-place succh that each unique element appears only once. Maintain the relative order of the unique elements and return the number of unique elements in nums. Let k be the count of unique elements. To pass the test cas ...

Posted on Wed, 15 Jul 2026 16:32:25 +0000 by Zallus

Linked List Algorithms: Pairwise Swapping, Targeted Removal, and Cycle Analysis

Swapping Adjacent Nodes in Pairs Manipulating node connections uniformly requires a sentinel (dummy) node to eliminate edge cases for the head element. To exchange adjacent pairs, position a reference pointer immediately before the pair undergoing modification. The iterative approach tracks three critical references: the node preceding the pair ...

Posted on Mon, 13 Jul 2026 17:21:33 +0000 by jon23d

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

Implementing Binary Search and In-Place Array Element Removal

Binary Search Implementation Given a sorted integer array nums with distinct elements and a target value, the objective is to locate the index of the target. If the target is not present, the function should return -1. Binary search efficiently reduces the search space by half in each iteration, but the implementation must strictly adhere to co ...

Posted on Sat, 04 Jul 2026 17:34:51 +0000 by hkothari

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