Grind75 Flashcards
Use a hash map to store the difference of the target and the current element as the key and the index as the value.
Best Time To Buy And Sell Stock,https://leetcode.com/problems/best-time-to-buy-and-sell-stock
Keep track of the minimum price and maximum profit while iterating through the list.
Majority Element,https://leetcode.com/problems/majority-element
Use Boyer-Moore Voting Algorithm to find the majority element.
Contains Duplicate,https://leetcode.com/problems/contains-duplicate
Use a set to check for duplicates.
Insert Interval,https://leetcode.com/problems/insert-interval
Merge intervals while iterating through the list.
3Sum,https://leetcode.com/problems/3sum
Sort the array and use three pointers to find the triplets.
Product Of Array Except Self,https://leetcode.com/problems/product-of-array-except-self
Use two arrays to store the product of all elements to the left and right of each element.
Combination Sum,https://leetcode.com/problems/combination-sum
Use backtracking to find all possible combinations.
Merge Intervals,https://leetcode.com/problems/merge-intervals
Sort intervals by starting point and merge overlapping intervals.
Sort Colors,https://leetcode.com/problems/sort-colors
Use the Dutch National Flag algorithm to sort the colors in one pass.
Container With Most Water,https://leetcode.com/problems/container-with-most-water
Use two pointers to find the maximum area.
Invert Binary Tree,https://leetcode.com/problems/invert-binary-tree
Use a recursive function to swap the left and right children of each node.
Balanced Binary Tree,https://leetcode.com/problems/balanced-binary-tree
Check if the difference in heights of the left and right subtrees is no more than one.
Diameter of Binary Tree,https://leetcode.com/problems/diameter-of-binary-tree
Use a recursive function to find the maximum depth of the left and right subtrees.
Maximum Depth of Binary Tree,https://leetcode.com/problems/maximum-depth-of-binary-tree
Use a recursive function to find the maximum depth.
Binary Tree Level Order Traversal,https://leetcode.com/problems/binary-tree-level-order-traversal
Use a queue to traverse the tree level by level.
Lowest Common Ancestor of a Binary Tree,https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree
Use a recursive function to find the lowest common ancestor.
Binary Tree Right Side View,https://leetcode.com/problems/binary-tree-right-side-view
Use a queue to traverse the tree level by level and add the rightmost node of each level to the result.
Construct Binary Tree from Preorder and Inorder Traversal,https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal
Use a recursive function to build the tree.
Serialize and Deserialize Binary Tree,https://leetcode.com/problems/serialize-and-deserialize-binary-tree
Use a queue to traverse the tree and serialize/deserialize it.
Valid Palindrome,https://leetcode.com/problems/valid-palindrome
Use two pointers to check if the string is a palindrome.
Valid Anagram,https://leetcode.com/problems/valid-anagram
Use a hash map to count the frequency of each character.
Longest Palindrome,https://leetcode.com/problems/longest-palindromic-substring
Use dynamic programming to find the longest palindromic substring.
Longest Substring Without Repeating Characters,https://leetcode.com/problems/longest-substring-without-repeating-characters
Use a sliding window to find the longest substring.
String to Integer (atoi),https://leetcode.com/problems/string-to-integer-atoi
Handle whitespaces, signs, and overflow while converting the string to an integer.
Longest Palindromic Substring,https://leetcode.com/problems/longest-palindromic-substring
Use dynamic programming to find the longest palindromic substring.
Find All Anagrams in a String,https://leetcode.com/problems/find-all-anagrams-in-a-string
Use a sliding window and a hash map to find all anagrams.