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.
All revision cards
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.
Either sort both strings and compare them, or build character frequency maps. The hash-map version is linear time and communicates counting skill well.
Check whether two strings contain the same characters with the same counts.
Walk the array once, keep the lowest price so far, and compute the best profit if you sold today.
Find the maximum profit from one buy and one sell of a stock price series.
Use left and right pointers, compute the middle index, and discard half the range each step based on the comparison.
Given a sorted list and a target, return the target index or -1 if it is missing.
Use a queue, process nodes in batches equal to the current queue size, and collect their children for the next level.
Return the nodes of a binary tree level by level.
Write a DFS helper that appends the current node before, between, or after visiting children depending on which traversal you are building.
Return the inorder, preorder, and postorder traversals of a binary tree.
Iterate through the string once and increment the count for each character so the result maps each distinct character to its frequency.
Return a frequency map for all characters in a string.
Each position depends on the previous two positions, so keep only the last two counts and build forward iteratively.
Return how many distinct ways there are to reach the top if you can climb 1 or 2 steps at a time.
Initialize a DP array with an impossible sentinel value, set dp[0] to zero, and for each amount try every coin to update the cheapest reachable solution.
Given coin denominations and a target amount, return the minimum number of coins needed to make that amount or -1 if it is impossible.
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.