String Manipulation Algorithms: From Basics to KMP Pattern Matching

String Reversal String reversal serves as a fundamental operation in string manipulation. While most programming languages provide built-in reverse functions, understanding the underlying mechanism is crucial for technical interviews. The approach uses two pointers starting from opposite ends of the string. These pointers move toward the center ...

Posted on Mon, 01 Jun 2026 16:25:58 +0000 by tecdesign

Computing Sorted Squares of a Non-Decreasing Integer Array

Method 1: Square then Sort This approach squares each element first and subsequently sorts the resulting array. #include <stdio.h> #include <stdlib.h> int compareElements(const void* first, const void* second) { int elemA = *((int*)first); int elemB = *((int*)second); if (elemA < elemB) return -1; if (elemA > elemB) r ...

Posted on Fri, 15 May 2026 09:48:25 +0000 by prc

Pairwise Node Swapping, Removing the Nth Node from End, Intersection of Linked Lists, and Detecting Cycles in Linked Lists

Pairwise Swapping of Adjacetn Nodes in a Linked List Given a linked list, swap every two adjacent nodes and return the head of the modified list. The operation must be performed by exchanging nodes, not by altering their internal values. Implementation approach: Use a dummy head node to simplify edge cases. Iterate through the list, adjusting p ...

Posted on Wed, 13 May 2026 12:01:00 +0000 by Averice

In-Place Filtering and Squaring of Sorted Arrays via Two-Pointer Techniques

Problem 1: In-Place Removal of Target Value Given an integer array nums and a integer val, remove every occurrence of val in place. The relative order of the remaining elements may change. Return the new length k such that the first k slots of nums contain all elements that are not equal to val. The rest of the array is ignored by the judge. Co ...

Posted on Sat, 09 May 2026 15:57:34 +0000 by jd57