DS Algo Questions
Written by haloboy777 on 2024-10-03
A set of DS Algo question that one should know before going for an interview
Arrays
- Repeat and Missing Number Array (InterviewBit)
- Find a Repeating and a Missing Number (GeeksforGeeks)
- Find Two Non-Repeating Elements in an Array (GeeksforGeeks)
- Find Maximum Sum Triplets (GeeksforGeeks)
- Stock Buy Sell (GeeksforGeeks)
- Find Maximum Number Possible by Doing at Most K Swaps (GeeksforGeeks)
- Minimum Number of Jumps to Reach End (GeeksforGeeks)
- Longest Increasing Subsequence (LeetCode) (Video Explanation)
- Form the Biggest Number (GeeksforGeeks)
- Search a Word in a 2D Grid (GeeksforGeeks)
- Trapping Rain Water (LeetCode)
- Max Points on a Line (LeetCode)
- Check If Array Pairs Are Divisible by K (LeetCode)
- Merge Intervals (LeetCode)
- Subarray Product Less Than K (LeetCode)
- 3Sum (LeetCode)
- Set Matrix Zeroes (LeetCode)
- Range Sum Query 2D (LeetCode)
- First Missing Positive (LeetCode)
- Top K Frequent Elements (LeetCode)
- Longest Palindromic Substring (LeetCode)
- Sort Colors (LeetCode)
- Maximum Points You Can Obtain from Cards (LeetCode)
Hashing
- 4Sum II (LeetCode)
- Longest Consecutive Sequence (LeetCode)
- LRU Cache (LeetCode)
- Longest Substring with Equal 1s and 0s (GeeksforGeeks)
- Range Module (LeetCode)
- My Calendar I (LeetCode)
- My Calendar II (LeetCode)
- My Calendar III (LeetCode)
- Time-Based Key-Value Store (LeetCode)
Cyclic Sort
Sorting
- Kth Largest Element in an Array (LeetCode)
- Count of Smaller Numbers After Self (LeetCode)
- Reverse Pairs (LeetCode)
- Top K Frequent Elements (LeetCode)
LinkedList
- Partition List (InterviewBit)
- Partition List (LeetCode)
- Palindrome List (InterviewBit)
- Palindrome Linked List (LeetCode)
- List Cycle (InterviewBit)
- Flattening a Linked List (GeeksforGeeks)
- Reverse a List in Groups (GeeksforGeeks)
- Reverse Nodes in K-Group (LeetCode)
String
- Group Anagrams (LeetCode)
- Find the Smallest Window Containing All Characters (GeeksforGeeks)
- Minimum Window Subsequence (LeetCode)
- Longest Substring with at Most K Distinct Characters (LeetCode)
Binary Search
- Allocate Minimum Number of Pages (GeeksforGeeks)
- Woodcutting Made Easy (InterviewBit)
- Kth Smallest Element in a Sorted Matrix (LeetCode)
- Maximum Length Possible by Cutting Woods (GeeksforGeeks)
- Median of Two Sorted Arrays (LeetCode)
- Kth Element in Two Sorted Arrays (GeeksforGeeks)
Heaps & Priority Queues
- Merge K Sorted Linked Lists Using Min-Heap (GeeksforGeeks)
- Merge K Sorted Lists (LeetCode)
- Nearly Sorted Algorithm (GeeksforGeeks)
- Top K Frequent Words (LeetCode)
- Find Median from Data Stream (LeetCode)
- Minimum Cost of Ropes (GeeksforGeeks)
- Sliding Window Median (LeetCode)
- Max Value of Equation (LeetCode)
- Trapping Rain Water II (LeetCode)
Stacks/Queues
- Sliding Window Maximum (GeeksforGeeks)
- Design a Stack That Supports GetMin (GeeksforGeeks)
- Min Stack (LeetCode)
- First Non-Repeating Character in a Stream (InterviewBit)
- Zigzag Tree Traversal (GeeksforGeeks)
- Binary Tree Zigzag Level Order Traversal (LeetCode)
- Sort a Stack Using Recursion (GeeksforGeeks)
- Largest Rectangle in Histogram (LeetCode)
- Maximal Rectangle (LeetCode)
- Max Rectangle in Binary Matrix (InterviewBit)
- Next Greater Element I (LeetCode)
- Valid Parenthesis String (LeetCode)
- Decode String (LeetCode)
- Car Fleet II (LeetCode)
Greedy
- Minimum Number of Platforms Required (GeeksforGeeks)
- Majority Element (GeeksforGeeks)
- Minimize Cash Flow Among Friends (GeeksforGeeks)
- Maximum Number of Overlapping Intervals (GeeksforGeeks)
- Task Scheduler (LeetCode)
- Guess the Word (LeetCode)
- Sentence Screen Fitting (LeetCode)
- Maximum Number of Events That Can Be Attended (LeetCode)
- Queue Reconstruction by Height (LeetCode)
- Random Pick with Blacklist (LeetCode)
- Random Pick with Blacklist - Java Discussion (LeetCode)
- Video Stitching (LeetCode)
Trees
- Check if Array Can Represent Preorder Traversal of BST (GeeksforGeeks)
- 2 Sum Binary Tree (InterviewBit)
- Find a Pair with Given Sum in BST (GeeksforGeeks)
- Two Sum IV - Input is a BST (LeetCode)
- Construct Binary Tree from Postorder and Inorder (GeeksforGeeks)
- Find Minimum Depth of a Binary Tree (GeeksforGeeks)
- Least Common Ancestor (InterviewBit)
- Flatten Binary Tree to Linked List (InterviewBit)
- Flatten Binary Tree to Linked List (LeetCode)
- Sorted Linked List to Balanced BST (GeeksforGeeks)
- Convert Sorted List to Binary Search Tree (LeetCode)
- Inorder Tree Traversal Without Recursion (GeeksforGeeks)
- Symmetric Tree - Tree Mirror Image of Itself (GeeksforGeeks)
- Minimum Iterations to Pass Information in Nodes (GeeksforGeeks)
- Query Ancestor-Descendant Relationship in Tree (GeeksforGeeks)
- Check if a Binary Tree is BST (GeeksforGeeks)
- Print Nodes at Distance K in Binary Tree (GeeksforGeeks)
- Construct BST from Preorder Traversal (GeeksforGeeks)
- Serialize/Deserialize Binary Tree (GeeksforGeeks)
- Shortest Distance Between Two Nodes in BST (GeeksforGeeks)
- Merge Two Binary Trees (InterviewBit)
- Binary Tree Zigzag Level Order Traversal (LeetCode)
- Connect Nodes at Same Level with O(1) Space (GeeksforGeeks)
- Maximum XOR of Two Numbers in an Array (LeetCode)
- Sum of Distances in Tree (LeetCode)
- Find Duplicate Subtrees (LeetCode)
- Binary Search Tree - Delete (GeeksforGeeks)
- Delete Node in a BST (LeetCode)
- Recover Binary Search Tree (LeetCode)
- Smallest Subtree with All the Deepest Nodes (LeetCode)
- Lowest Common Ancestor of Deepest Leaves (LeetCode)
Trie
- Find All Shortest Unique Prefixes to Represent Words (GeeksforGeeks)
- Shortest Unique Prefix (InterviewBit)
- Print All Anagrams Together (GeeksforGeeks)
- Design Search Autocomplete System (LeetCode)
DSU (Disjoint Set Union)
- Accounts Merge (LeetCode)
- Most Stones Removed with Same Row or Column (LeetCode)
- Checking Existence of Edge Length Limited Paths (LeetCode)
Graph
- Diameter of Binary Tree (LeetCode)
- Longest Path in an Undirected Tree (GeeksforGeeks)
- Topological Sorting (GeeksforGeeks)
- Clone an Undirected Graph (GeeksforGeeks)
- Word Ladder I (InterviewBit)
- Word Ladder Length of Shortest Chain (GeeksforGeeks)
- Detect Cycle in an Undirected Graph (GeeksforGeeks)
- Detect Cycle in a Graph (GeeksforGeeks)
- Find Precedence of Characters (GeeksforGeeks)
- Minimum Time for All Oranges to Rot (GeeksforGeeks)
- Graph Coloring - Greedy Algorithm (GeeksforGeeks)
- Snake and Ladder Problem (GeeksforGeeks)
- Dijkstra's Shortest Path Algorithm (GeeksforGeeks)
- 0/1 Matrix (LeetCode)
- Count Vowels Permutation (LeetCode)
- Count Vowels Permutation Discussion (LeetCode)
- Number of Ways to Paint N x 3 Grid (LeetCode)
- Critical Connections in a Network (LeetCode)
- Redundant Connection (LeetCode)
- Longest Increasing Path in a Matrix (LeetCode)
- Course Schedule II (LeetCode)
- Cheapest Flights Within K Stops (LeetCode)
- Path with Minimum Effort (LeetCode)
- String Transforms into Another String (LeetCode)
- Pacific Atlantic Water Flow (LeetCode)
- Path Rectangle Containing Circles (GeeksforGeeks)
- Couples Holding Hands - Java Solution (LeetCode)
- Couples Holding Hands (LeetCode)
- Minimum Cost to Make At Least One Valid Path in a Grid (LeetCode)
- 0-1 BFS Shortest Path in a Binary Graph (GeeksforGeeks)
- Shortest Path Visiting All Nodes (LeetCode)
- Shortest Path with Alternating Colors (LeetCode)
- Steps by Knight (GeeksforGeeks)
- Best Meeting Point (LeetCode)
- Shortest Distance from All Buildings (LeetCode)
- Walls and Gates (LeetCode)
- Confusing Number II (LeetCode)
- The Most Similar Path in a Graph (LeetCode)
- Jump Game IV (LeetCode)
- Loud and Rich (LeetCode)
- Where Will the Ball Fall (LeetCode)
- Count Pairs of Nodes (LeetCode)
DP (Dynamic Programming)
- Longest Palindromic Subsequence (GeeksforGeeks)
- Longest Palindromic Subsequence (LeetCode)
- Champagne Tower (LeetCode)
- Subset Sum Problem (GeeksforGeeks)
- Longest Common Subsequence (InterviewBit)
- Best Time to Buy and Sell Stock III (LeetCode)
- Best Time to Buy and Sell Stock III (YouTube)
- Best Time to Buy and Sell Stock IV (LeetCode)
- Best Time to Buy and Sell Stock IV (YouTube)
- Best Time to Buy and Sell Stock with Cooldown (LeetCode)
- Maximum Product Subarray (LeetCode)
- Decode Ways (LeetCode)
- Word Break II (LeetCode)
- Split Array Largest Sum (LeetCode)
- Perfect Squares (LeetCode)
- Minimum Cost for Tickets (LeetCode)
- Minimum Cost for Tickets Discussion (LeetCode)
- 2 Keys Keyboard (LeetCode)
- Dungeon Game (LeetCode)
- Dungeon Game (YouTube)
- Longest Arithmetic Subsequence (LeetCode)
- Triangle (LeetCode)
- Minimum Number of Refueling Stops (LeetCode)
- Best Time to Buy and Sell Stock with Transaction Fee (LeetCode)
- Encode String with Shortest Length (LeetCode)
- Regular Expression Matching (LeetCode)
- Minimum Swaps to Make Sequences Increasing (LeetCode)
- Stone Game III (LeetCode)
- Maximum Sum of 3 Non-Overlapping Subarrays (LeetCode)
- Burst Balloons (LeetCode)
- Predict the Winner (LeetCode)
- Optimal Strategy for a Game (GeeksforGeeks)
- Palindrome Partitioning (GeeksforGeeks)
- As Far from Land as Possible (LeetCode)
- Russian Doll Envelopes (LeetCode)
- Minimum Number of Removals to Make Mountain Array (LeetCode)
- Binary Tree Cameras (LeetCode)
- Make Array Strictly Increasing (LeetCode)
- Make Array Strictly Increasing Discussion (LeetCode)
- Race Car (LeetCode)
- New 21 Game (LeetCode)
- Cherry Pickup II (LeetCode)
- Cherry Pickup (LeetCode)
- House Robber III (LeetCode)