Number of Islands
Scan the grid cell by cell. When you find unvisited land, increment the island count and run DFS or BFS to mark every connected land cell as visited.
Count how many islands of connected land exist in a grid of '1' and '0' values.
Quick recall
Scan the grid cell by cell. When you find unvisited land, increment the island count and run DFS or BFS to mark every connected land cell as visited.
Count how many islands of connected land exist in a grid of '1' and '0' values.
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.
First store prefix products from the left, then multiply each position by a running suffix product from the right.
Return an array where each position contains the product of all other elements except itself.
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.
Walk the list node by node, reverse each next pointer, and move the window forward until the list is exhausted.
Reverse a singly linked list and return the new head.
Use slicing with a step of -1 for the shortest solution, or iterate from the end if the interviewer wants the mechanics.
Write a function that returns the input string reversed.
Normalize k by array length, then rebuild the order from the tail slice followed by the front slice.
Rotate an array to the right by k positions.
Store indices in a deque so values stay in decreasing order. Remove indices that fall out of the window and pop smaller trailing values before appending the current index.
Return the maximum value in each sliding window of size k.
Keep a running prefix sum and a hash map of how many times each prefix sum has appeared. For each new prefix, look for prefix minus k to count matching earlier starts.
Count how many contiguous subarrays sum to k.
Build a frequency map, then select the top k items by count using a heap-based helper or a bucket sort approach.
Return the k most frequent values from an integer list.
Store each seen number in a dictionary keyed by value. For each new number, check whether target minus number has already appeared.
Return the indices of two numbers that add up to a target.
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.