Most Important 50 Coding Questions
Array Problems
1. Find the Kth Largest/Smallest Element in an Array
o Use sorting or a heap to find the Kth element efficiently.
2. Maximum Subarray Sum (Kadane's Algorithm)
o Find the contiguous subarray with the maximum sum.
3. Merge Two Sorted Arrays
o Merge two sorted arrays into one sorted array.
4. Find Duplicate in an Array
o Find duplicate elements in an array using a hash set or cycle detection.
5. Sort an Array of 0s, 1s, and 2s (Dutch National Flag Problem)
o Sort an array containing only 0s, 1s, and 2s in linear time.
6. Find Missing Number in an Array
o Given an array containing n-1 numbers ranging from 1 to n, find the missing number.
7. Longest Consecutive Sequence
o Find the length of the longest consecutive elements sequence in an array.
8. Find All Pairs with a Given Sum
o Find all pairs of numbers in an array that sum up to a given target.
9. Move Zeroes to End of Array
o Move all zeros in an array to the end while maintaining the order of other elements.
10. Maximum Product Subarray
o Find the contiguous subarray with the maximum product.
String Problems
11. Reverse a String
o Reverse the characters in a string.
12. Check if Two Strings are Anagrams
o Determine if two strings are anagrams of each other.
13. Longest Palindromic Substring
o Find the longest palindromic substring in a given string.
14. Implement ATOI (String to Integer Conversion)
o Convert a string to an integer without using built-in functions.
15. Longest Common Prefix
o Find the longest common prefix string among an array of strings.
16. Longest Substring Without Repeating Characters
o Find the length of the longest substring without repeating characters.
17. Count and Say Problem
o Generate the nth term of the "count and say" sequence.
18. Valid Parentheses
o Check if a given string of parentheses is valid.
19. Find All Permutations of a String
o Generate all permutations of a given string.
20. Group Anagrams
o Group a list of strings into anagrams.
Linked List Problems
21. Reverse a Linked List
o Reverse the nodes of a linked list.
22. Detect and Remove Loop in Linked List
o Detect a loop in a linked list and remove it.
23. Merge Two Sorted Linked Lists
o Merge two sorted linked lists into one sorted list.
24. Find Intersection of Two Linked Lists
o Find the intersection point of two singly linked lists.
25. Check if Linked List is Palindrome
o Check if a singly linked list is a palindrome.
Tree Problems
26. In-order, Pre-order, Post-order Traversal
o Implement tree traversal methods (in-order, pre-order, post-order).
27. Lowest Common Ancestor in a Binary Tree
o Find the lowest common ancestor of two nodes in a binary tree.
28. Check if a Binary Tree is Balanced
o Check if a binary tree is height-balanced.
29. Level Order Traversal (BFS)
o Perform level order traversal of a binary tree.
30. Diameter of a Binary Tree
o Find the diameter of a binary tree.
Graph Problems
31. Depth First Search (DFS) and Breadth First Search (BFS)
o Implement DFS and BFS for graph traversal.
32. Detect Cycle in an Undirected Graph
o Check if an undirected graph contains a cycle.
33. Find the Shortest Path in an Unweighted Graph
o Use BFS to find the shortest path from a source node to all other nodes in an
unweighted graph.
34. Topological Sorting
o Perform topological sorting of a directed acyclic graph (DAG).
35. Number of Islands
o Find the number of islands in a 2D matrix using DFS or BFS.
Dynamic Programming Problems
36. 0/1 Knapsack Problem
o Solve the 0/1 knapsack problem using dynamic programming.
37. Longest Increasing Subsequence (LIS)
o Find the length of the longest increasing subsequence.
38. Coin Change Problem
o Find the minimum number of coins needed to make a given amount.
39. Longest Common Subsequence (LCS)
o Find the longest common subsequence between two strings.
40. Edit Distance
o Find the minimum number of operations required to convert one string to another.
Stack and Queue Problems
41. Implement Stack Using Queues
o Implement a stack using two queues.
42. Next Greater Element
o Find the next greater element for each element in an array.
43. Evaluate Postfix Expression
o Evaluate a postfix expression using a stack.
44. LRU Cache Implementation
o Design and implement an LRU (Least Recently Used) cache.
45. Sort a Stack
o Sort a stack using recursion.
Bit Manipulation Problems
46. Find the Single Number
o Find the element that appears only once in an array where every other element
appears twice.
47. Count Number of Set Bits
o Count the number of 1s (set bits) in the binary representation of a number.
48. Power of Two Check
o Check if a given number is a power of two.
Searching and Sorting Problems
49. Binary Search
o Implement binary search to find an element in a sorted array.
50. Merge Sort
o Implement the merge sort algorithm.