DSA Problem list
Arrays
1. Largest element in an array (gfg)
2. Smallest element in an array (gfg)
3. Second largest element in an array (gfg)
4. Second smallest element in an array (gfg)
5. Maximum Difference between Two Elements such that Larger
Element Appears after the Smaller Element (gfg)
6. Largest 3 distinct elements in an array (gfg)
7. Biotonic point (gfg)
8. Kth smallest element in an array (gfg)
9. Kth largest element in an array (leetcode)
10. Third largest element in an array (gfg)
11. Third largest element in an array(handles duplicates and use
of long type) (leetcode)
12. Largest element in an array after merge operations (leetcode)
13. Maximum in array generated (leetcode)
14. Check if array is sorted or not (gfg)
15. Check if array is sorted in ascending and descending(a
combination of both) (Extra)
16. Check if the array is sorted and rotated (leetcode)
17. Chef if array can be sorted by reversing one subarray (gfg)
18. Check if array can be sorted with one swap (gfg)
19. Remove duplicates from sorted array (gfg) (leetcode)
20. Remove duplicates from sorted array(copies of 2) (leetcode+)
21. Count hills and valleys in an array
22.
Binary Search
1. Binary search(iterative and recursive approach) (gfg) (leetcode)
https://www.geeksforgeeks.org/problems/binary-search-
1587115620/1
https://leetcode.com/problems/binary-search/
2. Search insert position of k (gfg) (leetcode)
3. Implementing lower bound (gfg)
4. Implementing upper bound (gfg)
5. Find the first and last occurrence of a given number (gfg) (leetcode)
6. Finding ceil of a number (gfg)
7. Finding floor of a number (gfg)
8. Number of occurences of an element in a sorted array (gfg)
9. Search in rotated sorted array-I(without duplicates) (gfg) (leetcode)
10. Search in rotated sorted array-II(with duplicates) (gfg) (leetcode)
11. Find minimum in rotated sorted array-I(without duplicates) (gfg)
(leetcode)
12. Find minimum in rotated sorted array-II(with duplicates) (gfg)
(leetcode)
13. Find how many times array has been rotated (gfg)
14. Find peak element in an array (gfg) (leetcode)
15. Find square root of a number (gfg) (leetcode)
16. Row with maximum ones (sorted matrix) (gfg) (2D-Matrix)
https://www.geeksforgeeks.org/problems/row-with-max-1s0023/1
17. Row with maximum ones (unsorted matrix) (leetcode) (2D-Matrix)
https://leetcode.com/problems/row-with-maximum-ones/
18. Search a 2D-matrix -I (gfg) (leetcode) (2D-Matrix)
https://leetcode.com/problems/search-a-2d-matrix/description/
19. Search a 2D-matrix -II (gfg) (leetcode) (2D-Matrix)
https://leetcode.com/problems/search-a-2d-matrix-ii/
20. Peak element-II (in a 2D matrix) (leetcode) (2D-Matrix)
21. Single number
22. Guess number higher or lower (leetcode)
https://leetcode.com/problems/guess-number-higher-or-lower/
23. Koko eating bananas
https://www.geeksforgeeks.org/problems/koko-eating-bananas/1
https://leetcode.com/problems/koko-eating-bananas/?
source=submission-ac
24. Find the smallest divisor given a threshold
https://leetcode.com/problems/find-the-smallest-divisor-given-a-
threshold/
25. Minimum number of days to make ‘M’ bouquets (gfg) (leetcode)
26. Allocate books (gfg) (leetcode)
27. Painter’s partition (gfg) (leetcode)
28. Split array largest sum (gfg) (leetcode)
29. Capacity to ship packages within d days (gfg) (leetcode)
30. Aggressive cows (gfg) (leetcode)
31. Median of two sorted arrays of different sizes (gfg) (leetcode)
32. Kth element of two sorted arrays (gfg)
Recursion
1. Print name N times (gfg)
2. Print numbers from 1 to N (gfg)
3. Print N terms from N to 1 (gfg)
4. Print linearly from 1 to N using backtracking (N,N) (gfg)
5. Print from N to 1 using backtracking(N,N) (Extra)
6. Sum of N terms (gfg)
7. Sum of series (gfg)
https://www.geeksforgeeks.org/problems/sum-of-first-n-terms5843/1
8. Factorial of a number (gfg)
9. Reverse an array (gfg)
10. Check if a string is palindrome or not (gfg)
11. Fibonocci series (gfg) (leetcode)
12. Combination Sum-I (gfg) (leetcode)
13. Combination Sum-II
14. Rat in a maze (gfg)
https://www.geeksforgeeks.org/problems/rat-in-a-maze-problem/1
15. Soduku solver
https://www.geeksforgeeks.org/problems/solve-the-sudoku-
1587115621/1
https://leetcode.com/problems/sudoku-solver/
16. N-queens
https://leetcode.com/problems/n-queens/
https://www.geeksforgeeks.org/problems/n-queen-problem0315/1
17. Palindrome partitioning
https://leetcode.com/problems/palindrome-partitioning/
https://www.geeksforgeeks.org/problems/find-all-possible-
palindromic-partitions-of-a-string/1
18. Knights Tour
https://leetcode.com/problems/check-knight-tour-configuration/
Binary trees
1. Preorder traversal (gfg) (leetcode)
https://www.geeksforgeeks.org/problems/preorder-traversal/1
https://leetcode.com/problems/binary-tree-preorder-traversal/
2. Inorder traversal (gfg) (leetcode)
https://leetcode.com/problems/binary-tree-inorder-traversal/
https://www.geeksforgeeks.org/problems/inorder-traversal/1
3. Postorder traversal (gfg) (leetcode)
https://leetcode.com/problems/binary-tree-postorder-traversal/
https://www.geeksforgeeks.org/problems/postorder-traversal/1
4. Level order traversal (gfg) (leetcode)
https://www.geeksforgeeks.org/problems/level-order-traversal/1
https://leetcode.com/problems/binary-tree-level-order-traversal/
5. Iterative preorder traversal (gfg)
https://www.geeksforgeeks.org/problems/preorder-traversal-
iterative/1
6. Iterative inorder traversal
https://www.geeksforgeeks.org/problems/inorder-traversal-
iterative/1
7. Iterative postorder traversal(using 2 stacks)
https://www.geeksforgeeks.org/problems/postorder-traversal-
iterative/1
8. Iterative postorder traversal(using 1 stack)
https://www.geeksforgeeks.org/problems/postorder-traversal-
iterative/1
9. Preorder, inorder and postorder traversals in one stot
10. Maximum depth of binary tree
https://www.geeksforgeeks.org/problems/maximum-depth-of-binary-
tree/1
https://leetcode.com/problems/maximum-depth-of-binary-tree/
11. Check for balanced binary tree
https://leetcode.com/problems/balanced-binary-tree/
https://www.geeksforgeeks.org/problems/check-for-balanced-tree/1
12. Diameter of a binary tree
https://leetcode.com/problems/diameter-of-binary-tree/
https://www.geeksforgeeks.org/problems/diameter-of-binary-tree/1
13. Maximum path sum in Binary tree
https://www.geeksforgeeks.org/problems/maximum-path-sum-from-
any-node/1
https://leetcode.com/problems/binary-tree-maximum-path-sum/
14. Check if two trees are identical
https://www.geeksforgeeks.org/problems/determine-if-two-trees-are-
identical/1
https://leetcode.com/problems/same-tree/
15. Zig-zag traversal
https://leetcode.com/problems/binary-tree-zigzag-level-order-
traversal/
https://www.geeksforgeeks.org/problems/zigzag-tree-traversal/1
16. Boundary traversal
https://www.geeksforgeeks.org/problems/boundary-traversal-of-
binary-tree/1
17. Vertical order traversal
https://leetcode.com/problems/vertical-order-traversal-of-a-binary-
tree/
18. Vertical tree traversal
https://www.geeksforgeeks.org/problems/print-a-binary-tree-in-
vertical-order/1
19. Top view of BT
https://www.geeksforgeeks.org/problems/top-view-of-binary-tree/1
20. Bottom view of BT
https://www.geeksforgeeks.org/problems/bottom-view-of-binary-
tree/1
21. Left view of BT
https://www.geeksforgeeks.org/problems/left-view-of-binary-tree/1
22. Right view of BT
https://www.geeksforgeeks.org/problems/right-view-of-binary-tree/1
https://leetcode.com/problems/binary-tree-right-side-view/
23. Check for symmetric BT
https://www.geeksforgeeks.org/problems/symmetric-tree/1
https://leetcode.com/problems/symmetric-tree/
24. Print root to given node path in BT
25. Print root to leaf path in BT
Var1: https://leetcode.com/problems/binary-tree-paths/
Var2: https://www.geeksforgeeks.org/problems/root-to-leaf-paths/1
26. Least common ancestor
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-
tree/
https://www.geeksforgeeks.org/problems/lowest-common-ancestor-
in-a-binary-tree/1
27. Maximum number of nodes considering all levels
https://www.geeksforgeeks.org/problems/maximum-width-of-tree/1
28. Maximum width of BT
https://leetcode.com/problems/maximum-width-of-binary-tree/
29. Modifying the BT so that it satisfies the Children sum property
void helper(TreeNode* root){
if(root==NULL)
return;
int child=0;
//Initially the summation of left and the right partners have
to be calculated
if(root->left) child+=root->left->val;
if(root->right) child+=root->right->val;
//If the child's value is greater than root,
//then replace the value of the root with the child's value
to increase it
if(child>=root->data){
root->val=child;
}
//If the child's value is lesser than child
//then replace each of the partner's value with the root's
value
else{
if(root->left) root->left->val=root->val;
else if(root->right) root->right->val=root->val;
}
//then move left and right
helper(root->left);
helper(root->right);
int tot=0;
if(root->left) tot+=root->left->val;
if(root->right) tot+=root->right->val;
if(root->left || root->right) root->val=tot;
}
30. Check if the BT satisfies the child sum property
https://leetcode.com/problems/root-equals-sum-of-children/
https://www.geeksforgeeks.org/problems/children-sum-parent/1
31. Print all the nodes at a distance k
Var1: target is given as int
https://www.geeksforgeeks.org/problems/nodes-at-given-distance-in-
binary-tree/1
Var2: target is given as node https://leetcode.com/problems/all-
nodes-distance-k-in-binary-tree/
32. Maximum time to burn down all BT
https://www.geeksforgeeks.org/problems/burning-tree/1
https://leetcode.com/problems/amount-of-time-for-binary-tree-to-be-
infected/
33. Count the total number of nodes in a complete BT
https://www.geeksforgeeks.org/problems/count-number-of-nodes-in-
a-binary-tree/1
https://leetcode.com/problems/count-complete-tree-nodes/
34. Requirements to construct unique BT
https://www.geeksforgeeks.org/problems/unique-binary-tree-
requirements/1
35. Construct a BT from preorder and inorder traversals
https://www.geeksforgeeks.org/problems/construct-tree-1/1
https://leetcode.com/problems/construct-binary-tree-from-preorder-
and-inorder-traversal/submissions/1724470110/
36. Construct a BT from postorder and inorder traversals
https://www.geeksforgeeks.org/problems/tree-from-postorder-and-
inorder/1
https://leetcode.com/problems/construct-binary-tree-from-inorder-
and-postorder-traversal/
37. Serialisation and deserialization
Var1: https://leetcode.com/problems/serialize-and-deserialize-binary-
tree/submissions/1724562306/
Var2: https://www.geeksforgeeks.org/problems/serialize-and-
deserialize-a-binary-tree/1
38. Flatten a BT into a LL
https://leetcode.com/problems/flatten-binary-tree-to-linked-list/
https://www.geeksforgeeks.org/problems/flatten-binary-tree-to-
linked-list/1
39.
Binary search tree
1. Search in BST
Var1: Return the node address of the search element
https://leetcode.com/problems/search-in-a-binary-search-tree/
Var2: Check if the search element is present or not
https://www.geeksforgeeks.org/problems/search-a-node-in-bst/1
2. Ceil in BST
https://www.geeksforgeeks.org/problems/implementing-ceil-in-bst/1
3. Floor in BST
https://www.geeksforgeeks.org/problems/floor-in-bst/0
4. Insert in BST
https://www.geeksforgeeks.org/problems/insert-a-node-in-a-bst/1
https://leetcode.com/problems/insert-into-a-binary-search-tree/
5. Delete in BST
6. Kth smallest element in BST
https://leetcode.com/problems/kth-smallest-element-in-a-bst/
submissions/1725232723/
https://www.geeksforgeeks.org/problems/find-k-th-smallest-element-
in-bst/1
7. Kth largest element in BST
https://www.geeksforgeeks.org/problems/kth-largest-element-in-
bst/1
8. Check if a tree is BST or not
https://leetcode.com/problems/validate-binary-search-tree/
submissions/1725263239/
https://www.geeksforgeeks.org/problems/check-for-bst/1
9. Lowest common ancestor of BT
https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-
search-tree/
https://www.geeksforgeeks.org/problems/lowest-common-ancestor-
in-a-bst/1
10. Construct BST from preorder traversal
https://leetcode.com/problems/construct-binary-search-tree-from-
preorder-traversal/
https://www.geeksforgeeks.org/problems/preorder-to-
postorder4423/1
11. Inorder successor
https://www.geeksforgeeks.org/problems/inorder-successor-in-bst/1
12. Inorder predecessor
https://www.geeksforgeeks.org/problems/predecessor-and-
successor/1
13. BST iterator
https://leetcode.com/problems/binary-search-tree-iterator/
submissions/1725539894/
14. Two sum in a BST
Brute and Better :
https://www.geeksforgeeks.org/problems/find-a-pair-with-given-
target-in-bst/1
Optimal:
https://leetcode.com/problems/two-sum-iv-input-is-a-bst/
submissions/1725618491/
15. Recover BST
https://leetcode.com/problems/recover-binary-search-tree/
https://www.geeksforgeeks.org/problems/fixed-two-nodes-of-a-bst/1
Hashing
1. ASCII sum range
Strings
1. Reverse a string
2. Check if a string is palindrome/not
3. Valid palindrome
4. Remove all occurences of a substring from the string
5. Reverse words in string
6. String compression problem
7. Valid anagram
8. Largest odd number in string
9. Isomorphic strings
10. Consecutive characters
11. Word pattern
12. Sum of beauty strings
13. Permutation in strings
14. Maximum Nesting Depth of the Parentheses
Heap
1. Implementing heap insertion
2. Implementing heap deletion
3. Building a heap(2 methods)
4. Heap sort
5. Implementing priority queue
6. Height of heap
https://www.geeksforgeeks.org/problems/height-of-heap5025/1
7. Minimum cost of ropes
https://www.geeksforgeeks.org/problems/minimum-cost-of-ropes-
1587115620/1
8. Magician and chocolates
9. Last stone weight
https://leetcode.com/problems/last-stone-weight/
10. Take gifts from the richest pile
https://leetcode.com/problems/take-gifts-from-the-richest-pile/
description/
11. Profit maximization
https://www.interviewbit.com/problems/profit-maximisation/
12. Kth largest element
13. Kth smallest element
14. Kth largest element in a stream
Var1: https://leetcode.com/problems/kth-largest-element-in-a-
stream/
Var2:
Sorting
1. Heap sort
2. Merge sort
3. Quick sort
4. Count sort
5. Radix sort
POTD
1. Roman to integer(strings)
https://leetcode.com/problems/roman-to-integer/submissions/
1725863588/
https://www.geeksforgeeks.org/problems/roman-number-to-
integer3201/1
2. Difference check
https://www.geeksforgeeks.org/problems/difference-check/1