CategoryProblemKey Concepts/StrategiesDetailed ExplanationCode Example
Arrays & HashingContains DuplicateUse a set to track seen numbersIterate through the array, adding each element to the set; return true if an element is already in the set.image-20240704195345712
Valid AnagramUse a hashmap to count character frequenciesCount characters in both strings using hashmaps and compare the counts.image-20240705120140625 image-20240705134225476
Two SumUse a hashmap to store indices of elementsIterate through the array, for each element, check if the complement (target - element) exists in the hashmap.image-20240705144707139 image-20240705161435368
Two PointersValid PalindromeUse two pointers to compare characters from both endsInitialize two pointers at the beginning and end of the string, move towards the center, and compare characters.image-20240705165706033 image-20240705171252877
3SumSort the array, use two pointers to find tripletsAfter sorting, fix one element and use two pointers to find pairs that sum up to the target value.image-20240705183649120
Container With Most WaterUse two pointers from both ends, move towards the centerStart with two pointers at the ends of the array, calculate area, and move the pointer pointing to the shorter line.image-20240705200503598
Sliding WindowBest Time to Buy and Sell StockTrack the minimum price and maximum profitIterate through prices, keeping track of the minimum price so far and calculating the maximum profit at each step.image-20240705214121415
Longest Substring Without Repeating CharactersUse a sliding window and a set to track charactersUse a set to keep track of characters in the current window, move the window if a duplicate is found.image-20240705235055067 image-20240705235715853
StackValid ParenthesesUse a stack to match opening and closing bracketsPush opening brackets onto the stack, pop for closing brackets, ensuring they match.image-20240706141704875
Binary SearchSearch in Rotated Sorted ArrayModify binary search to handle rotationDetermine which half is sorted, then use binary search logic on the sorted half.image-20240706211210199
Find Minimum in Rotated Sorted ArrayUse binary search with rotation considerationSimilar to searching in a rotated array, adjust the binary search to find the minimum element.image-20240706192608358
Linked ListReverse Linked ListIterate and reverse pointersUse three pointers to reverse the direction of the list iteratively.image-20240707125402250
Merge Two Sorted ListsUse a dummy node to merge iterativelyUse a dummy node to simplify merging two lists, iteratively comparing and linking nodes.image-20240707155826322
Reorder ListFind middle, reverse second half, mergeSplit the list, reverse the second half, and merge the two halves by alternating nodes.image-20240411163057801
TreesBinary Tree Inorder TraversalUse recursion or a stackTraverse left subtree, visit the node, then traverse the right subtree.
Validate Binary Search TreeUse in-order traversal to check orderPerform an in-order traversal and ensure each value is greater than the previous one.
Same TreeUse recursion to compare nodesRecursively compare corresponding nodes in both trees.
TriesImplement Trie (Prefix Tree)Use a TrieNode class to insert and searchUse a nested TrieNode class to represent nodes, with methods for insert, search, and startsWith.
Dynamic ProgrammingClimbing StairsUse DP array or memoizationUse an array where each entry represents the number of ways to reach that step.
House RobberUse a DP array to track maximum lootUse a DP array where each entry represents the maximum amount of money that can be robbed up to that house.
Coin ChangeUse a DP array to track the minimum coinsUse a DP array where each entry represents the minimum number of coins needed for that amount.
GraphsNumber of IslandsUse DFS/BFS to mark visited islandsUse DFS or BFS to traverse and mark all connected lands (islands) as visited.
Clone GraphUse DFS/BFS and a hashmap for copiesUse DFS or BFS with a hashmap to store already cloned nodes.
Course ScheduleUse DFS to detect cyclesPerform a DFS and use a state array to detect cycles in the graph.
IntervalsMerge IntervalsSort intervals, then merge overlapping onesSort intervals by start time, then iterate through and merge overlapping intervals.
Insert IntervalInsert and merge as necessaryInsert the new interval into the list, then merge overlapping intervals.
Meeting RoomsSort intervals and check for overlapsSort intervals by start time, use a min-heap to track end times of ongoing meetings.
StringsLongest Substring Without Repeating CharactersUse sliding window and a hashmapUse a sliding window to maintain a window of unique characters, updating the start of the window when a duplicate is found.
Longest Palindromic SubstringUse DP or expand around center approachUse dynamic programming to track palindromes or expand around each character to find the longest palindrome.
Longest Common PrefixCompare characters of each stringCompare characters of each string one by one until a mismatch is found.
BacktrackingSubsetsUse backtracking to generate all subsetsRecursively build subsets, choosing to include or exclude each element.
Combination SumUse backtracking to find combinationsRecursively build combinations, subtracting from the target, and avoiding duplicates.
PermutationsUse backtracking to generate permutationsRecursively generate permutations by swapping elements.
Heap / Priority QueueTop K Frequent ElementsUse a hashmap and a heapUse a hashmap to count frequencies, then use a heap to find the top K elements.
Find Median from Data StreamUse two heaps to maintain the medianUse a max-heap for the lower half and a min-heap for the upper half of the data stream.
GreedyBest Time to Buy and Sell Stock IISum up all the increasing differencesIterate through the array, summing up all positive differences between consecutive days.
Jump GameTrack the farthest reach possibleIterate through the array, updating the maximum reachable index and checking if the end is reachable.
Bit ManipulationSingle NumberUse XOR to find the unique numberXOR all elements, as XOR of two identical numbers is zero, and XOR of a number with zero is the number itself.
MatrixSet Matrix ZeroesUse first row/column as markersUse the first row and column to mark zero rows and columns, then iterate and set zeros accordingly.
Spiral MatrixTraverse in layers and change directionsUse loops to traverse the matrix in a spiral order, changing direction at boundaries.
Rotate ImageTranspose and then reverse rowsTranspose the matrix (swap rows and columns) and then reverse each row.
MiscellaneousLRU CacheUse an ordered dictionaryUse an ordered dictionary to maintain insertion order and implement LRU logic.
Min StackUse two stacks for value and minimumUse one stack for all values and another stack to keep track of minimum values.