Tag view

#two-pointers

Cross-subject tag search for related interview cards.

Clear

Results update as you type. Press / to jump straight into search.

Tagged with two-pointers

10 cards

Coding Exercises Medium O(n^2)

3 Sum

Sort the array, fix one value at a time, and use two pointers on the remaining range. Skip duplicate anchors and duplicate pointer values so the result contains unique triplets only.

Return all unique triplets in an array whose sum is zero.

Coding Exercises Medium O(n)

Container With Most Water

Use left and right pointers, compute the current area, and always move the side with the smaller height because only that can improve the limiting wall.

Find two lines that together hold the maximum area of water.

Coding Exercises Easy O(n)

Move Zeroes

Scan once, swap each non-zero value into the next write position, and advance that write pointer.

Move all zeroes to the end of the list while keeping the relative order of non-zero values.

Coding Exercises Easy O(n)

Palindrome Check

Compare characters from the left and right ends while moving inward. Normalize case or strip non-alphanumeric characters only if the prompt requires it.

Determine whether a string reads the same forward and backward.

Coding Exercises Medium O(n)

Remove Nth Node From End

Use a dummy node, move the fast pointer n steps ahead, then move both fast and slow together until fast reaches the end. The slow pointer will be just before the node to remove.

Remove the nth node from the end of a linked list and return the head.

Coding Exercises Easy O(n)

Two Sum II (Sorted Array)

Start with one pointer at the left and one at the right. Move the left pointer rightward when the sum is too small and the right pointer leftward when the sum is too large.

Given a sorted array, return the indices of two numbers that add up to a target.