Arrays
0/23
✓
01
Find the Second Largest Element in an Array
Single pass, track two max values. Don't sort — O(n) required.
✓
03
Rotate Array by K Positions (Left/Right)
Reverse approach: reverse all → reverse first k → reverse rest. O(n).
✓
05
Find Missing Number in Array (1 to N)
Sum formula: N*(N+1)/2 - sum(arr). Or XOR approach.
✓
07
Two Sum — Find Pair with Given Sum
HashMap approach: for each num, check if (target-num) exists. O(n).
✓
08
Sort Array of 0s, 1s, and 2s (Dutch National Flag)
Three-pointer: low, mid, high. Single pass O(n). TCS favourite!
✓
09
Maximum Subarray Sum (Kadane's Algorithm)
Track currentMax and globalMax. Reset current when negative. THE classic.
✓
10
Remove Duplicates from Sorted Array (In-place)
Two-pointer: slow writes unique, fast scans. Return new length.
✓
12
Find Majority Element (> N/2 times)
Boyer-Moore Voting. O(n) time, O(1) space. Very elegant.
✓
12b
Majority Element II (> N/3 times)
Extended Boyer-Moore: track two candidates. Verify in second pass. At most 2 results.
✓
14
Check if Array is Sorted and Rotated
Count breaks (where arr[i] > arr[i+1]). At most 1 break allowed.
✓
15
Maximum Product Subarray
Track both max and min product (negatives flip). Similar to Kadane's.
✓
17
Leaders in an Array
Traverse from right, track max. Element is leader if > all right elements.
✓
18
Next Permutation
Find rightmost ascending pair, swap, reverse suffix. Classic pattern.
✓
19
Longest Consecutive Sequence
HashSet: for each num, if num-1 not in set → count streak forward.
✓
20
Find Union & Intersection of Two Sorted Arrays
Two-pointer merge approach. Handle duplicates across both arrays.
✓
21
Best Time to Buy and Sell Stock
Track min price so far, compute profit at each day. One pass O(n). TCS classic!
✓
22
Rearrange Positive & Negative Numbers Alternately
Separate positives/negatives, interleave. Or two-pointer partition approach.
Strings
0/19
✓
23
Check if String is Palindrome
Two-pointer from both ends. Handle case-insensitive + ignore non-alpha.
✓
24
Reverse a String / Reverse Words in a String
Split by space, reverse array, join. Handle multiple spaces.
✓
25
Check if Two Strings are Anagrams
Frequency count with array[26] or HashMap. Compare counts.
✓
26
Count Vowels and Consonants in a String
Simple traversal. Use a set for vowel check. Handle uppercase.
✓
27
First Non-Repeating Character
HashMap for frequency, then second pass to find first with count=1.
✓
28
Most Frequent Character in a String
Frequency array. Track max frequency and corresponding char.
✓
29
Remove All Occurrences of a Character
Simple filter/replace. Know your language's string methods.
✓
29b
Remove Duplicates from a String
Use LinkedHashSet or boolean visited[26] to keep first occurrence only.
✓
30
Check if String Contains Only Digits
Iterate and check ASCII range or use isdigit(). Edge: empty string.
✓
31
Longest Substring Without Repeating Characters
Sliding window + HashSet. Shrink left when duplicate found.
✓
32
Count Words in a String
Split by spaces, filter empty strings, count. Handle multiple spaces.
✓
33
Longest Palindromic Substring
Expand around center for each char (odd+even length). O(n²).
✓
35
Check if One String is a Rotation of Another
Concatenate s1+s1, then check if s2 is a substring. Clever O(n).
✓
37
String Compression (Run-Length Encoding)
Count consecutive chars: "aabbbcc" → "a2b3c2". Watch output format.
✓
38
Longest Common Prefix
Compare char by char across all strings. Stop at first mismatch.
✓
39
Valid Parentheses (Balanced Brackets)
Use a stack. Push opening, pop on closing and match. Classic.
✓
40
Roman to Integer / Integer to Roman
Map roman chars to values. If smaller before larger → subtract.
Number Theory & Math
0/17
✓
42
Reverse a Number / Check Palindrome Number
Build reversed number digit by digit. Compare with original.
✓
43
Fibonacci Series (Iterative + Recursive + DP)
Know all 3 approaches. Iterative is O(n) time O(1) space. Best for TCS.
✓
44
Factorial of a Number (Iterative + Recursive)
Simple loop. Watch overflow for large N — use long/BigInteger.
✓
46
Armstrong Number Check
Sum of digits^(number of digits) == number itself. 153 → 1³+5³+3³=153.
✓
49
Sum of Digits / Digital Root / Number of Digits
Extract digits with %10 and /10. Digital root: keep summing till single digit. Count digits with log10.
✓
50
Decimal to Binary / Binary to Decimal Conversion
Use repeated /2 and %2 for D→B. Positional multiplication for B→D.
✓
51
Sieve of Eratosthenes (All Primes up to N)
Boolean array, mark multiples of each prime. O(n log log n).
✓
52
Power of Two / Power of Three Check
Bit manipulation: n & (n-1) == 0 for power of 2. Or keep dividing.
✓
54
Modular Exponentiation (Power with Modulo)
Binary exponentiation: square and multiply. Needed for large inputs.
✓
55
Neon Number / Spy Number / Automorphic Number
TCS loves these number-type checks. Quick implementations.
✓
56
Count Factors / Divisors of a Number
Loop from 1 to √n, if n%i==0, count both i and n/i. O(√n).
✓
57
Count Number of Digits in a Number
Use log10(n)+1 or repeated /10 loop. Handle n=0 edge case.
Sorting & Searching
0/10
✓
58
Binary Search (Iterative + Recursive)
left=0, right=n-1, mid=(left+right)/2. Know both implementations cold.
✓
59
Search in Rotated Sorted Array
Modified binary search: check which half is sorted, then decide.
✓
60
Find First and Last Position of Element
Two binary searches: one for leftmost, one for rightmost occurrence.
✓
61
Bubble Sort Implementation
Know the algorithm, time complexity O(n²). TCS asks to implement sorts.
✓
62
Selection Sort Implementation
Find min in unsorted part, swap to front. O(n²) but easy to code.
✓
63
Merge Sort Implementation
Divide and conquer. O(n log n). Understand merge step thoroughly.
✓
64
Find Peak Element
Binary search: if mid > mid+1, peak is on left side (including mid).
✓
65
Find Square Root (Integer) using Binary Search
Binary search between 1 and n. Check mid*mid <= n < (mid+1)*(mid+1).
✓
66
Find Floor and Ceil of a Number in Sorted Array
Modified binary search. Floor: largest ≤ target. Ceil: smallest ≥ target.
✓
67
Kth Smallest/Largest Element
Use QuickSelect O(n) avg or sort+index O(n log n). Know both.
HashMap & Frequency Counting
0/9
✓
68
Frequency of Each Element in Array
HashMap: key=element, value=count. Print all. Foundation skill.
✓
69
Find All Duplicates in an Array
HashMap count > 1. Or mark visited by negating index (O(1) space trick).
✓
71
Top K Frequent Elements
HashMap for frequency → sort by freq → return top K. Or bucket sort.
✓
72
Count Pairs with Given Sum
For each element, check if (sum - element) exists in map. Handle duplicates.
✓
73
First Element to Occur K Times
HashMap: increment count on each element. Return first with count == K.
✓
74
Longest Subarray with Sum K (Positives + Negatives)
Prefix sum + HashMap. Store first occurrence of each prefix sum.
✓
75
Contains Duplicate II (Within K Distance)
Sliding window with HashSet of size K. Or HashMap storing last index.
✓
76
Count Distinct Elements in Array
Insert all elements into HashSet. Set size = distinct count. O(n).
Sliding Window & Two Pointer
0/8
✓
78
Smallest Subarray with Sum ≥ S
Variable-size window: expand right, shrink left when sum ≥ S. Track min.
✓
79
Count Subarrays with Given XOR / Sum
Prefix sum/XOR + HashMap for counting. Important pattern.
✓
80
Container With Most Water
Two-pointer from both ends. Move shorter pointer inward. O(n).
✓
81
3Sum (Find All Triplets with Sum = 0)
Sort → fix one → two-pointer for remaining. Skip duplicates.
✓
82
Move Negative Numbers to One Side
Two-pointer partition. Similar to Dutch flag but simpler.
✓
83
Trapping Rain Water
Two-pointer or prefix max arrays. Calculate water at each index. Classic.
✓
84
Minimum Window Substring
Variable window + frequency map. Expand right to cover all chars, shrink left to minimize. O(n).
Matrix Operations
0/8
✓
85
Transpose of a Matrix
Swap matrix[i][j] with matrix[j][i]. For in-place: only upper triangle.
✓
86
Spiral Order Matrix Traversal
4 pointers: top, bottom, left, right. Traverse boundaries, shrink inward.
✓
89
Matrix Multiplication
Triple nested loop: C[i][j] += A[i][k] * B[k][j]. Know dimensions rule.
✓
90
Search in Sorted 2D Matrix
Start top-right. If target < current go left, else go down. O(m+n).
✓
91
Diagonal Traversal of Matrix
Primary diagonal: i==j. Secondary: i+j==n-1. Traverse both diagonals separately.
✓
92
Row-wise and Column-wise Sum of Matrix
Nested loops: sum each row and each column separately. TCS basic matrix question.
Trees (For Prime)
0/10
✓
93
Inorder, Preorder, Postorder Traversal (Recursive + Iterative)
Know all 3 traversals cold. Recursive is easy, iterative uses stack. Foundation of trees.
✓
94
Level Order Traversal (BFS on Tree)
Use a queue. Process level by level. Foundation for many tree problems.
✓
95
Height / Maximum Depth of Binary Tree
Recursive: max(left, right) + 1. Base: null → 0. Classic DFS.
✓
96
Check if Binary Tree is Balanced
Height difference of left & right subtrees ≤ 1 at every node. O(n) with combined height check.
✓
97
Diameter of Binary Tree
Longest path between any two nodes. At each node: leftHeight + rightHeight. Track global max.
✓
98
Mirror / Symmetric Tree Check
Recursive: left.left mirrors right.right and vice versa. Clean base cases.
✓
99
Lowest Common Ancestor (LCA) of Binary Tree
If both nodes found in left/right → current node is LCA. Classic recursion.
✓
100
Validate Binary Search Tree (BST)
Inorder traversal must be sorted. Or pass min/max bounds recursively. Important BST concept.
✓
101
Search & Insert in BST
Search: compare and go left or right. Insert: find null position. Know both recursive & iterative.
✓
102
Left View / Right View / Top View of Binary Tree
Level order + track first/last node per level. Or recursive with depth tracking.
Graphs (For Prime)
0/8
✓
103
BFS (Breadth-First Search) on Graph
Queue-based traversal. Use visited array. Level-by-level exploration. Foundation of graph problems.
✓
104
DFS (Depth-First Search) on Graph
Stack or recursion. Mark visited. Explore as deep as possible before backtracking.
✓
105
Detect Cycle in Undirected Graph
BFS/DFS + parent tracking. If visited neighbor ≠ parent → cycle exists.
✓
106
Detect Cycle in Directed Graph
DFS with recursion stack (3-color: white/gray/black). Gray→Gray = cycle.
✓
107
Number of Islands (Connected Components)
Grid DFS/BFS: for each unvisited '1', start traversal and mark all connected. Count components.
✓
108
Shortest Path in Unweighted Graph (BFS)
BFS naturally finds shortest path in unweighted graphs. Track distance array.
✓
109
Topological Sort (Kahn's BFS / DFS)
DAG ordering: process nodes with 0 in-degree first. Or DFS with post-order stack.
✓
110
Dijkstra's Shortest Path (Weighted Graph)
Min-heap + greedy relaxation. dist[src]=0, relax neighbors. O((V+E) log V).
Dynamic Programming (For Prime)
0/12
✓
111
Climbing Stairs (Fibonacci DP)
dp[i] = dp[i-1] + dp[i-2]. Base: dp[0]=1, dp[1]=1. Classic intro to DP.
✓
113
Longest Common Subsequence (LCS)
2D table: if chars match dp[i][j]=dp[i-1][j-1]+1, else max of top/left.
✓
114
Coin Change (Min Coins)
1D DP: dp[amount] = min coins. For each coin, dp[j] = min(dp[j], dp[j-coin]+1).
✓
115
Longest Increasing Subsequence (LIS)
O(n²) DP or O(n log n) with binary search. Know both.
✓
116
House Robber (Max Non-Adjacent Sum)
dp[i] = max(dp[i-1], dp[i-2]+nums[i]). Simple 1D DP.
✓
117
Min Path Sum in Grid
dp[i][j] = grid[i][j] + min(dp[i-1][j], dp[i][j-1]). Standard 2D DP.
✓
119
Subset Sum Problem
dp[i][j] = can we form sum j using first i items? Boolean 2D DP. Key knapsack variant.
✓
120
Unique Paths in Grid
dp[i][j] = dp[i-1][j] + dp[i][j-1]. Count ways to reach bottom-right from top-left.
✓
121
Palindrome Partitioning (Min Cuts)
dp[i] = min cuts for s[0..i] to be all palindromes. Pre-compute palindrome check table.
Greedy
0/4
✓
123
Activity Selection Problem
Sort by end time. Pick first, skip overlapping, pick next non-overlapping.
✓
124
Fractional Knapsack
Sort by value/weight ratio. Take as much as possible of most valuable.
✓
125
Minimum Coins for Change (Greedy Approach)
For standard denominations, greedy works. Pick largest coin first.
✓
126
Pattern Printing (Number/Star Triangles)
Nested loops: outer for rows, inner for spaces + stars. 5-6 patterns.
Recursion & Backtracking
0/6
✓
127
Generate All Subsets (Power Set)
Recursive: include/exclude each element. Or bitmask iteration.
✓
128
Generate All Permutations of a String/Array
Recursive swap at each position. Backtrack after recursive call.
✓
131
Sum of Digits using Recursion
Base: n==0 return 0. Recursive: n%10 + sumOfDigits(n/10). Pure recursion practice.
✓
132
Reverse String / Array using Recursion
Swap first and last, recurse on inner. Base: start >= end. O(n).