Linked List Manipulation Techniques for Common Interview Problems
Swapping Adjacent Nodes in Pairs
To exchange every two consecutive nodes in a singly linked list:
Introduce a dummy node to simplify edge cases.
Use a pointer to traverse and perform swaps iterative.
Ensure loop termination checks prevent null dereferencing.
class Node:
def __init__(self, value=0, nxt=None):
self.value = value
...
Posted on Sun, 19 Jul 2026 16:51:10 +0000 by lostprophetpunk
Efficient Solution for Two-Interval Sum Problem Using Two-Pointer Technique
Problem AnalysisThe problem requires finding, for each position i in an array, the maximum value k such that the sum of elements in the left interval [i, i+k-1] and the sum of elements in the right interval [i+k, i+2*k-1] are both less than or equal to a given value s.Why Binary Search FailsAt first glance, one might consider using binary searc ...
Posted on Thu, 16 Jul 2026 17:10:43 +0000 by flattened
Efficient Array Processing Using Two-Pointer Techniques
In-place modification refers to operations pefrormed directly on the original data structure without allocating new storage. For duplicate removal, a naive approach would involve creating a new array to store unique elements, but in-place constraints require modifying the existing array and returning its new effective length.
When dealing with ...
Posted on Sat, 27 Jun 2026 17:33:44 +0000 by jigsawsoul
In-Place Matrix Rotation: Clockwise 90-Degree Transformation
Problem Statement
Given an n × n 2D matrix representing an image, rotate the image clockwise by 90 degrees. The rotation must be performed in-place without using an auxiliary matrix.
Algorithm Approach
The clockwise rotation can be achieved through two sequential operations:
Transpose along the main diagonal — swap rows and columns
Mirror each ...
Posted on Wed, 24 Jun 2026 16:52:12 +0000 by littledragon
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