Questions Solve to become expert in DSA in JAVA
I. Arrays (15 Questions)
. Find the maximum and minimum element in an array.
1
2. Reverse an array in place.
3. Rotate an array by ksteps (cyclically).
4. Find the "Kth" largest and smallest element in an array.
5. Sort an array of 0s, 1s, and 2s (Dutch National Flag Problem).
6. Move all negative numbers to one side of the array.
7. Find the union and intersection of two arrays.
8. Find duplicates in an array of nelements.
9. Find the contiguous subarray with the maximum sum (Kadane’s Algorithm).
10.Find the longest consecutive subsequence in an array.
11.Trapping Rainwater Problem.
12.Find all pairs on an integer array whose sum is equal to a given number.
13.Merge two sorted arrays without extra space.
14.Find the majority element in an array (appears more than n/2 times).
15.Count inversions in an array.
II. Strings (10 Questions)
6.Check if a string is a palindrome.
1
17.Reverse words in a given string.
18.Check whether two strings are anagrams.
19.Find the first non-repeating character in a string.
20.Count and say problem (generate nth term of the count-and-say sequence).
21.Find all permutations of a string.
22.Implement the strStr()function (substring search).
23.Longest Palindromic Substring.
24.Check if a string contains only digits.
25.Convert a string to an integer without using built-in functions.
III. Searching and Sorting (10 Questions)
6.Binary Search in a sorted array.
2
27.Find the square root of a number (using binary search).
28.Search an element in a rotated sorted array.
29.Find the peak element in an array.
0.Implement Bubble Sort.
3
31.Implement Selection Sort.
32.Implement Merge Sort.
33.Implement Quick Sort.
34.Find the kth smallest/largest element using QuickSelect.
35.Count the number of times a sorted array is rotated.
IV. Linked Lists (15 Questions)
6.Reverse a singly linked list.
3
37.Detect and remove a cycle in a linked list.
38.Find the middle of a linked list.
39.Merge two sorted linked lists.
40.Check if a linked list is a palindrome.
41.Remove duplicates from a sorted linked list.
42.Remove duplicates from an unsorted linked list.
43.Delete a node in a linked list without the head pointer.
44.Add two numbers represented by linked lists.
45.Flatten a multilevel doubly linked list.
46.Rotate a linked list by k places.
47.Find the intersection point of two linked lists.
48.Clone a linked list with a random pointer.
49.Sort a linked list using merge sort.
50.Convert a binary tree to a doubly linked list.
V. Stacks and Queues (10 Questions)
1.Implement a stack using arrays.
5
52.Implement a stack using two queues.
53.Implement a queue using two stacks.
54.Evaluate a postfix expression.
55.Implement the Next Greater Element (NGE) problem.
56.Implement the Stock Span Problem.
57.Check for balanced parentheses in an expression.
58.Design a Min Stack (supports push pop
, getMinin O(1)).
, and
59.Implement a Circular Queue.
60.Find the first negative integer in every window of size k.
VI. Binary Trees (15 Questions)
1.Perform in-order, pre-order, and post-order traversal of a binary tree.
6
62.Level order traversal of a binary tree.
3.Check if two binary trees are identical.
6
64.Find the height of a binary tree.
65.Find the diameter of a binary tree.
66.Convert a binary tree into its mirror.
67.Check if a binary tree is balanced.
68.Count the number of nodes in a complete binary tree.
69.Find the Lowest Common Ancestor (LCA) of two nodes.
70.Check if a binary tree is a Binary Search Tree (BST).
71.Serialize and deserialize a binary tree.
72.Print all nodes at distance k from a given node.
73.Boundary traversal of a binary tree.
74.Construct a binary tree from inorder and preorder traversals.
75.Find the maximum path sum in a binary tree.
VII. Graphs (15 Questions)
6.Implement Depth First Search (DFS).
7
77.Implement Breadth First Search (BFS).
78.Detect a cycle in an undirected graph using BFS/DFS.
79.Detect a cycle in a directed graph using BFS/DFS.
80.Find the shortest path in an unweighted graph.
81.Find the shortest path in a weighted graph using Dijkstra’s algorithm.
82.Find the shortest path in a graph with negative weights using Bellman-Ford.
83.Implement the Floyd-Warshall Algorithm.
84.Find connected components in an undirected graph.
85.Topological Sort using Kahn’s Algorithm.
86.Find the MST (Minimum Spanning Tree) using Kruskal’s Algorithm.
87.Find the MST using Prim’s Algorithm.
88.Check if a graph is bipartite.
89.Count the number of islands in a 2D grid (Graph-based DFS).
90.Implement the Traveling Salesman Problem using DP.
VIII. Dynamic Programming (15 Questions)
1.Fibonacci series using DP.
9
92.Longest Increasing Subsequence.
93.Longest Common Subsequence.
94.Edit Distance (Levenshtein Distance).
95.0/1 Knapsack Problem.
96.Minimum coin change problem.
97.Subset Sum Problem.
98.Rod Cutting Problem.
99.Count ways to reach the nth stair.
100. Maximum Subarray Sum using DP.
01.
1 atrix Chain Multiplication.
M
102. Minimum Path Sum in a grid.
103. Maximum Profit in the Stock Market (1 transaction allowed).
104. Maximum Profit in the Stock Market (multiple transactions allowed).
105. Partition problem (can the array be partitioned into two subsets with equal sum?).
IX. Tricky Problems and System Design (10 Questions)
06.
1 Implement an LRU Cache.
107. Design a Snake and Ladder game.
108. Implement a Rate Limiter using sliding windows.
109. Find the median of a data stream.
110. Implement a Trie (Prefix Tree) with insert, search, and startsWith methods.
111. Solve the N-Queens problem.
112. Word Break Problem.
113. Find the number of ways to decode a string of digits.
114. Design a Twitter-like feed system.
115. Implement a Concurrent Queue in Java.