Competitive Programming Questions
Two Pointers
- #75 Sort Colors
- #80 Remove Duplicates from Sorted Array II
- #88 Merge Sorted Array
- #457 Circular Array Loop
- #713 Subarray Product Less Than K
- #845 Longest Mountain in Array
- #904 Fruit into baskets
- #925 Long Pressed name
- #986 Interval list intersections
Binary Search
- #33 Search in rotated sorted array
- #69 Sqrt(x)
- #153 Find min in rotated sorted array
- #349 Intersection of two arrays
- #441 Arranging coins
- #475 Heaters
- #658 Find K closest elements
- #911 Online Election
Hashmap
- #463 Island Perimeter
- #535 Encode and decode TinyURL
- #575 Distribute Candies
- #739 Daily Temperatures
- #748 Shortest Completing Word
- #811 Subdomain visit count
- #884 Uncommon words from Twos sentences
- #953 Verifying an Alien Dictionary
- #961 N-Repeated Element in Size 2N Array
- #1160 Find words that can be formed by characters
- #1078 Occurences after bigram
Stack
- #496 Next Greater Element I
- #682 Baseball Game
- #856 Score of Parentheses
- #946 Validate Stack Sequences
- #1190 Reverse Substrings Between Each Pair of Parentheses
- #1209 Remove All Adjacent Duplicates in String II
String
- #468 Validate IP Address
- #522 Longest Uncommon Subsequence II
- #539 Minimum Time Difference
- #553 Optimal Division
- #791 Custom Sort String
- #833 Find and replace in String
- #835 Image Overlap
- #893 Groups of Special-Equivalent Strings
- #1156 Swap For Longest Repeated Character Substring
Sliding Window
- #424 Longest Repeating Character Replacement
- #1040 Moving Stones Until Consecutive II
Tree
- #101 Symmetric Tree
- #108 Convert Sorted Array to Binary Search Tree
- #226 Invert Binary Tree
- #538 Convert BST to Greater Tree
- #543 Diameter of a Binary Tree
- #637 Average of Levels in Binary Tree
- #654 Maximum Binary Tree
- #669 Trim a Binary Search Tree
- #589 N-ary Tree Preorder Traversal
- #894 All Possible Full Binary Trees
- #979 Distribute Coins in Binary Tree
- #993 Cousins in a Binary Tree
- #1022 Sum of Root To Leaf Binary Numbers
- #1104 Path In Zigzag Labelled Binary Tree
- #1110 Delete Nodes And Return Forest
Competitive programming coding patterns
https://levelup.gitconnected.com/dont-just-leetcode-follow-the-coding-patterns-instead-4beb6a197fdb
10 golden rules for solving a coding question in an interview
- if we are dealing with top/maximum/minimum/closest k' elements among 'n' elements, we will be using a heap.
- If the given input is a sorted array or a list, we will either be using binray search or the two pointers.
- If we need to try all combinations (or permutations) of the input, we can either use backtracking or breadth first search.
- Most of the questions related to trees or graphs can be solved either through breadth first search or depth first search.
- Every recursive solution can be converted to an iterative solution using a stack.
- For a problem involving arrays, if there exists a solution in o(n^2)time and o(1) space, there must exist two other solutions:
- using a hashmap or a set for o(n) time and o(n) space
- using sorting for o(n log n) time and o(1) space.
- If a problem is asking for optimization (e. G. , maximization or minimization), we will be using dynamic programming.
- If we need to find some common substring among a set of strings, we will be using a hashmap or a trie.
- If we need to search/manipulate a bunch of strings, trie will be the best data structure.
- If the problem is related to a linkedlist and we can't use extra space, then use the fast & slow pointer approach.