A comprehensive collection of Data Structures & Algorithms implemented in Java — covering core concepts, LeetCode problems, HackerRank challenges, and interview prep organized by topic.
280+ Java files · 40+ topic directories
- Sorting
- Recursion
- Binary Search
- Hashing & HashMap
- Linked List
- Stack
- Queue
- Heap / Priority Queue
- Greedy
- Backtracking
- Binary Tree
- BST
- Graphs
- Dynamic Programming
- Segment Tree
- Trie
- Bit Manipulation
- LastRun Series (Recent Practice)
- HackerRank
- LeetCode Scratch / Misc
qustions/sorting/
| File | Algorithm |
|---|---|
bubble.java |
Bubble Sort |
insertion.java |
Insertion Sort |
merge.java |
Merge Sort |
selection.java |
Selection Sort |
Recursion/
| File | Problem |
|---|---|
ReverseString.java |
Reverse a string |
StringSubSequence.java |
All subsequences of a string |
StringSubSequenceWithoutRepeatedAnswer.java |
Unique subsequences |
arrayIsSorted.java |
Check if array is sorted |
checkDuplicate.java |
Check duplicates recursively |
findDuplicateInString.java |
Find duplicate in string |
firstAndLastOccur.java |
First and last occurrence |
keyPadCombinations.java |
Keypad letter combinations |
moveXtoLast.java |
Move element X to end |
towerOfHanoi_.java |
Tower of Hanoi |
Hard Questions — Recursion/Hard Questions/
| File | Problem |
|---|---|
Place1XMTilesInNXM.java |
Tile placement |
expressionAddOperator.java |
Expression add operators |
inviteNpeopleEitherSingleOrInPair.java |
Invitation combinations |
pathInMazeFrom0_0ToM_N.java |
Maze path finding |
permutationOfLetters.java |
Letter permutations |
subsetOfNNatualNum.java |
Subsets of N natural numbers |
BinarySearch/
| File | Problem |
|---|---|
FindFloor.java |
Floor in sorted array |
MinPairSum.java |
Minimum pair sum |
Hashing/
| File | Concept |
|---|---|
hasingBasics.java |
Hashing fundamentals |
iterationInHashMap.java |
HashMap iteration patterns |
hash methods implementations/hashimplementation.java |
Custom hash implementation |
HashMap/
| File | Problem |
|---|---|
UnionOfTwoArr.java |
Union of two arrays |
hashImplimentation.java |
HashMap implementation |
intersection.java |
Intersection of arrays |
iternaryFromTickets.java |
Itinerary from tickets |
majorityElement.java |
Majority element |
sumOfSubArray.java |
Subarray sum |
Hash Set/ — directory available for future problems
LinkedList/
| File | Problem |
|---|---|
removeZeroSumSublists.java |
Remove zero-sum sublists |
leetcode/ll/
| File | Problem |
|---|---|
One.java |
LL problem 1 |
double.java |
Doubly linked list |
example/one_one.java |
LL example |
26Stack/
| File | Concept |
|---|---|
Implementation.java |
Stack from scratch |
reverseStack.java |
Reverse a stack |
stackCollFrameWork.java |
Stack via Java Collections |
stackInLL.java |
Stack using linked list |
validparanthsis.java |
Valid parentheses |
26Stack/Hard Question/
| File | Problem |
|---|---|
findMaxAreaInAHistogram.java |
Largest rectangle in histogram |
26Stack/findNextGreatestNum/
| File | Problem |
|---|---|
StacknextGreatestNum.java |
Next greater element (stack) |
nextGreatestNum.java |
Next greater element |
26Stack/amazon/
| File | Problem |
|---|---|
pushAtTheBottom.java |
Push element to bottom |
26Stack/google and microsoft/
| File | Problem |
|---|---|
duplicateParanthesis.java |
Duplicate parentheses |
microsoft/
| File | Problem |
|---|---|
stockSpanProb.java |
Stock span problem |
Queue/
| File | Concept |
|---|---|
queueJavaCollectionFrameWork.java |
Queue via Java Collections |
reverse.java |
Reverse a queue |
interleave2halvesInQueue.java |
Interleave two halves |
Queue/array/
| File | Concept |
|---|---|
buildQueue.java |
Queue using array |
circularQueue.java |
Circular queue |
Queue/linkedlist/
| File | Concept |
|---|---|
generalQueue.java |
Queue using linked list |
Queue/deque/
| File | Concept |
|---|---|
deque_1.java |
Deque basics |
StackUsingdeque.java |
Stack using deque |
queueUsingDeque.java |
Queue using deque |
Queue/Intuit/
| File | Problem |
|---|---|
stackUsingTwoQueue.java |
Stack using two queues |
Queue/microsoftandgoogle/
| File | Problem |
|---|---|
queueUsingTwoStacks.java |
Queue using two stacks |
Queue/flipkart/
| File | Problem |
|---|---|
firstNonRepeatingLetter.java |
First non-repeating character |
Queue/problems/
| File | Problem |
|---|---|
binaryNums.java |
Binary numbers using queue |
Heap/
| File | Concept / Problem |
|---|---|
insert.java |
Heap insertion |
heapSort.java |
Heap sort |
priorityQueue.java |
PriorityQueue basics |
PQ_implement_comparable.java |
PQ with Comparable |
connectNRopesWithMinCost.java |
Connect ropes minimum cost |
nearByCar.java |
K nearest cars |
slidingWindow.java |
Sliding window maximum |
weakestSoldier.java |
K weakest rows |
greedy/
| File | Problem |
|---|---|
MaximumChainLength.java |
Maximum chain length |
chocolaProblem.java |
Chocola problem |
fractionalKnapsack.java |
Fractional knapsack |
indianCoin.java |
Indian coin change |
jobSequenceProblem.java |
Job sequencing |
minAbsoluteDiffPairs.java |
Minimum absolute diff pairs |
greedy/morganStan_MIcrosoft/
| File | Problem |
|---|---|
activitySelection.java |
Activity selection |
activitySelectionUsing2DArray.java |
Activity selection (2D) |
BackTracking/
| File | Problem |
|---|---|
NQueen.java |
N-Queens problem |
sudokusolver.java |
Sudoku solver |
BinaryTree/
| File | Concept / Problem |
|---|---|
bulidTree.java |
Build binary tree |
bfs.java |
BFS traversal |
heightOfTree.java |
Height of tree |
diameterOfATree.java |
Diameter of tree |
subTreeOfAnotherTree.java |
Subtree check |
NaryTreeLevelOrder.java |
N-ary tree level order |
narraytreenode.java |
N-ary tree node |
topOfTheTree.java |
Top view of tree |
BinaryTree2/
| File | Problem |
|---|---|
KthAncestor.java |
Kth ancestor of a node |
minimumDistance.java |
Minimum distance between nodes |
sumTree.java |
Sum tree check |
BinaryTree2/KthElement/
| File | Approach |
|---|---|
KthElementRecursivly.java |
Recursive |
KthElementInTheTreeIterativly.java |
Iterative |
BinaryTree2/LCA/
| File | Approach |
|---|---|
lowestCommonAncestor.java |
Basic LCA |
lowestCommonAncestorOptimized.java |
Optimized LCA |
BinaryTree2/Additional Basic Questions/
| File | Problem |
|---|---|
deleteNode.java |
Delete node |
univalidBinaryTreeOrNot.java |
Univalued tree check |
mirrorOfAGivenTree.java |
Mirror of a tree |
BST1/
| File | Concept |
|---|---|
build.java |
Build a BST |
mirrorOfBst.java |
Mirror of BST |
BST2/
| File | Problem |
|---|---|
BstToBalancedBST.java |
BST to balanced BST |
RecoverBST.java |
Recover BST |
SortedArrToBalancedTree.java |
Sorted array to balanced BST |
TwoSumBST.java |
Two sum in BST |
maxSumBST.java |
Maximum sum BST |
merge2BST.java |
Merge two BSTs |
validBST.java |
Validate BST |
leetcode/BST/
| File | Problem |
|---|---|
topoftree.java |
Top of BST |
morise_traversal/morisPreorder.java |
Morris preorder traversal |
Graphs/
| File | Concept / Problem |
|---|---|
createGraph.java |
Graph creation |
graph.java |
Graph basics |
bfs.java |
BFS traversal |
dfs.java (in Tree traversal/) |
DFS traversal |
hasPath.java |
Has path check |
allPathToTarget.java |
All paths to target |
topologicalSort.java |
Topological sort |
dijkstras.java |
Dijkstra's algorithm |
Graphs/Tree traversal/
| File | Traversal |
|---|---|
bfs.java |
BFS |
dfs.java |
DFS |
Solution.java |
Combined solution |
DP/
| File | Problem |
|---|---|
fibonacci.java |
Fibonacci |
minimumArrayJump.java |
Minimum jumps |
DP/0_1_knapsack/
| File | Approach |
|---|---|
knap_recursion.java |
Recursion |
knap_memoization.java |
Memoization |
knap_tabulation.java |
Tabulation |
DP/climbing stair/
| File | Approach |
|---|---|
climbingStairs.java |
Basic |
memo_climbingStair.java |
Memoization |
tabul_climbing.java |
Tabulation |
DP/Catalan Number/
| File | Problem / Approach |
|---|---|
Recursive_catalan.java |
Recursive |
memoization_catalan.java |
Memoization |
tabulation_catalan.java |
Tabulation |
CountBST.java |
Count unique BSTs |
mountainRange.java |
Mountain ranges |
DP/Matrix multiplication/
| File | Approach |
|---|---|
Rec_mcm.java |
Recursive MCM |
memoization_mcm.java |
Memoization MCM |
tabulation_mcm.java |
Tabulation MCM |
DP/least_Common_Factor/
| File | Problem |
|---|---|
lcs.java |
LCS basic |
lcs_Memoization.java |
LCS memoization |
lcs_Tab.java |
LCS tabulation |
editDistance.java |
Edit distance |
stringConversion.java |
String conversion |
wildcard.java |
Wildcard matching |
least largest sequence/longSeq.java |
Longest sequence |
lstcommonsubstring/lcs.java |
Longest common substring |
DP/minimum_Partationing/
| File | Problem |
|---|---|
mpm.java |
Minimum partition |
DP/rod_cutting/
| File | Problem |
|---|---|
rod1.java |
Rod cutting |
Segment Tree/
| File | Operation |
|---|---|
segmentTree.java |
Build segment tree |
minMaxST.java |
Min/max segment tree |
get_minMaxST.java |
Query min/max |
queriesInST.java |
Range queries |
updateInST.java |
Point update |
update_MinMaxST.java |
Update min/max |
LastRun10_trie/
| File | Problem |
|---|---|
LongestCommonSuffixQueries.java |
Longest common suffix queries |
LastRun3/BitManipulation/
| File | Problem |
|---|---|
BinaryGap.java |
Binary gap |
These directories represent the most recent problem-solving sessions, organized by topic.
LastRun/Tree/
| File | Problem |
|---|---|
BinaryTreeInorderIterative.java |
Inorder traversal (iterative) |
BinaryTreePreorderIterative.java |
Preorder traversal (iterative) |
BinaryTreePostorderIterative.java |
Postorder traversal (iterative) |
BinaryTreeLevelOrderRecursive.java |
Level order (recursive) |
BuildTreeFromPreorderInorder.java |
Build tree from preorder + inorder |
BuildTreeFromInorderPostorder.java |
Build tree from inorder + postorder |
DiameterOfBinaryTree .java |
Diameter of binary tree |
BalancedBinaryTree.java |
Check balanced tree |
MaxPathSumBinaryTree.java |
Maximum path sum |
LowestCommonAncestorBinaryTree.java |
LCA in binary tree |
FlattenBinaryTree.java |
Flatten to linked list |
SerializeDeserializeBinaryTree.java |
Serialize/Deserialize |
CountNodesBinaryTree.java |
Count nodes |
DistanceKBinaryTree.java |
Nodes at distance K |
AmountOfTimeToInfectTree.java |
Time to infect tree |
FindBottomLeftValue.java |
Bottom-left tree value |
SameTree.java |
Same tree check |
ChildrenSumProperty.java |
Children sum property |
MinRemoval.java |
Min removal |
MinimumCost.java |
Minimum cost |
MinimumDeletionsBalancedString.java |
Min deletions for balanced string |
LastRun2/BST/
| File | Problem |
|---|---|
SearchInBST.java |
Search in BST |
InsertIntoBST.java |
Insert into BST |
DeleteNodeInBst.java |
Delete node in BST |
ValidateBST.java |
Validate BST |
ValidateBSTInorder.java |
Validate BST (inorder) |
KthSmallestInBST.java |
Kth smallest element |
FloorInBST.java |
Floor in BST |
InorderSuccessorBST.java |
Inorder successor |
LCAinBST.java |
LCA in BST |
BSTIteratorDemo.java |
BST iterator |
CountNodesBinaryTree.java |
Count nodes |
FlipEquivalentBinaryTrees.java |
Flip equivalent trees |
LastRun2/Tree/
| File | Problem |
|---|---|
Create_Binary_Tree_From_Descriptions.java |
Build tree from descriptions |
Number of Ways to Assign Edge Weights/assignEdgeWeights_I.java |
Edge weights I |
Number of Ways to Assign Edge Weights/assignEdgeWeights_II.java |
Edge weights II |
LastRun4/
| File | Problem |
|---|---|
DigitorialPermutation.java |
Digitorial permutation |
LastRun5/Strings/
| File | Problem |
|---|---|
EvaluateBracketPairsOfString.java |
1807. Evaluate the Bracket Pairs of a String (Medium) |
FindTargetIndicesAfterSortingArray.java |
2089. Find Target Indices After Sorting Array (Easy) |
MaxDepthAfterSplit.java |
1111. Maximum Nesting Depth of Two Valid Parentheses Strings (Medium) |
MaximumActiveSectionsAfterTrade.java |
Maximum Active Sections After Trade |
MaximumNestingDepthOfParentheses.java |
1614. Maximum Nesting Depth of the Parentheses (Easy) |
MaxAlternatingSumOfSquares.java |
Maximum alternating sum of squares |
MaxSumOfSquares.java |
3723. Maximize Sum of Squares of Digits (Easy) |
MinAddToMakeValid.java |
921. Minimum Add to Make Parentheses Valid (Medium) |
MinDeletionsAdjacentXorNonZero.java |
Minimum Deletions to Make Adjacent Elements Bitwise XOR Non-Zero (Easy) |
MinInsertionsToBalance.java |
1541. Minimum Insertions to Balance a Parentheses String (Medium) |
MinOperationsAlternatingString.java |
1758. Minimum Changes To Make Alternating Binary String (Easy) |
MinOperationsToSortAPermutation.java |
3942. Minimum Operations to Sort a Permutation (Medium) |
MinSwapsSortByDigitSum.java |
3551. Minimum Swaps to Sort by Digit Sum (Medium) |
MinSumSquareDiff.java |
2333. Minimum Sum of Squared Difference (Medium) |
PalindromicSubstrings.java |
647. Palindromic Substrings (Medium) |
passwordStrengthCheck.java |
Password strength check |
PermutationInString.java |
567. Permutation in String (Medium) |
ProcessString.java |
Process string |
ReverseParentheses.java |
1190. Reverse Substrings Between Each Pair of Parentheses (Medium) |
RemoveInvalidParentheses.java |
301. Remove Invalid Parentheses (Hard) |
ScoreOfParentheses.java |
856. Score of Parentheses (Medium) |
SmallestPalindrome.java |
2697. Lexicographically Smallest Palindrome (Easy) |
SmallestSubsequenceOfDistinctCharacters.java |
1081. Smallest Subsequence of Distinct Characters (Medium) |
SumOfSquaresSpecial.java |
2778. Sum of Squares of Special Elements (Easy) |
ValidParentheses.java |
20. Valid Parentheses (Easy) |
WeightedWordMapping.java |
Weighted word mapping |
count no of special character Series/count_no_of_specical_char_I.java |
Count special chars I |
count no of special character Series/count_no_of_specical_char_II.java |
Count special chars II |
LastRun6/Graph/
| File | Problem |
|---|---|
FloodFill.java |
Flood fill |
RottingOranges.java |
Rotting oranges |
NumberofEnclaves.java |
Number of enclaves |
SurroundedRegion.java |
Surrounded regions |
MakeNetworkConnected.java |
Make network connected |
MakingALargeIsland.java |
Making a large island |
NetworkDelayTime.java |
Network delay time |
CheapestFlightsWithinKStops.java |
Cheapest flights within K stops |
FindCityWithSmallestNeighbors.java |
Find city with fewest neighbors |
NumberofWaystoArriveatDestination.java |
Number of ways to destination |
CourseScheduleII.java |
Course Schedule II |
wordLadder.java |
Word Ladder |
wordLadder2.java |
Word Ladder II |
shortestPathinAmaze.java |
Shortest path in maze |
MinCost.java |
Minimum cost path |
minNumberOfSeconds.java |
Minimum number of seconds |
mergerAccount_graph.java |
Merge accounts |
SwimInRisingWater.java |
Swim in rising water |
LastRun6/LastRun_Array/
| File | Problem |
|---|---|
HardRotatedArrayMinValue.java |
Min value in rotated array |
_350.java |
Intersection of two arrays II |
LastRun7/arrays/
| File | Problem |
|---|---|
CapacityToShipPackagesWithinDDays.java |
Ship packages within D days |
LeftRightDifference.java |
Left-right difference |
PartitionArrayAccordingtoGivenPivot.java |
Partition array by pivot |
RotatingtheBox.java |
Rotating the box |
MinimumCostOfBuyingCandiesWithDiscount.java |
Min cost buying candies |
MinimumIndexCapacity.java |
Minimum index capacity |
SmallestBalancedIndex.java |
Smallest balanced index |
Count_Kth_Roots_in_a_Range.java |
Count Kth roots in range |
longestCommonPrefix.java |
Longest common prefix |
LastRun7/Land and water park rides complete ques/
| File | Problem |
|---|---|
earliest_finish_time_for_land_and_water_rides_i.java |
Earliest finish time I |
earliest_finish_time_for_land_and_water_rides_ii.java |
Earliest finish time II |
LastRun7/Total Wavieness in a number/
| File | Problem |
|---|---|
TotalWavinessOfNumbersInRangeI.java |
Total waviness in range I |
TotalWavinessOfNumbersInRangeII.java |
Total waviness in range II |
LastRun7/max total subarray value/
| File | Problem |
|---|---|
MaximumTotalSubarrayValueI.java |
Max subarray value I |
MaximumTotalSubarrayValueII.java |
Max subarray value II |
LastRun7/Matrix_And_Score/
| File | Problem |
|---|---|
Minimum_Cost_to_Make_at_Least_One_Valid_Path_in_a_Grid.java |
Min cost valid path in grid |
LastRun8_DP/
| File | Problem |
|---|---|
HouseRobberII.java |
House Robber II |
Minimum_Path_Sum.java |
Minimum path sum |
Triangle.java |
Triangle minimum path |
UniquePathsII.java |
Unique paths II |
PartitionEqualSubsetsum.java |
Partition equal subset sum |
isInterleave.java |
Interleaving string |
LastRun8_DP/jump games/
| File | Problem |
|---|---|
JumpGame1.java |
Jump Game I |
JumpGame2.java |
Jump Game II |
JumpGame3.java |
Jump Game III |
JumpGame4.java |
Jump Game IV |
JumpGame5.java |
Jump Game V |
jumpGame6.java |
Jump Game VI |
JumpGame7.java |
Jump Game VII |
jumpGame9.java |
Jump Game IX |
LastRun8_DP/DP/
| File | Problem |
|---|---|
MaximumAmountGrid.java |
Maximum amount in grid |
maxWallsRobotsCanBreak.java |
Max walls robots can break |
LastRun9_Hashing/
| File | Problem |
|---|---|
LongestConsecutiveSequence.java |
Longest consecutive sequence |
TopKFrequentElements.java |
Top K frequent elements |
LastRun_Stack/
| File | Problem |
|---|---|
Evaluate_Reverse_Polish_Notation.java |
Evaluate Reverse Polish Notation |
Evaluate_Reverse_Polish_Notation_optimized.java |
RPN (optimized) |
LastRun_greedy/
| File | Problem |
|---|---|
MaximumMatrixSum.java |
Maximum matrix sum |
MinimumInitialEnergyToFinishTasks.java |
Min initial energy for tasks |
destroyAsteroids.java |
Destroy asteroids |
LastRun_linkedList/
| File | Problem |
|---|---|
DeleteMiddleOfLinkedList.java |
Delete middle node |
MaximumTwinSumOfALinkedList.java |
Maximum twin sum |
PartitionLinkedList.java |
Partition linked list |
LastRun_Senior_Staff_maths/
| File | Problem |
|---|---|
ProcessStringKthCharacter.java |
Process string Kth character |
HackerRank/
Organized by category — directories are ready for more solutions.
| Directory | Files |
|---|---|
Hashing/ |
icecreamParlor.java |
Strings/ |
PalindromeCheck.java, palindromeIndex_.java, Solution.java |
Arrays/ |
(empty — ready) |
DynamicProgramming/ |
(empty — ready) |
Graphs/ |
(empty — ready) |
Greedy/ |
(empty — ready) |
LinkedList/ |
(empty — ready) |
Recursion/ |
(empty — ready) |
Searching/ |
(empty — ready) |
Sorting/ |
(empty — ready) |
Stack/ |
(empty — ready) |
Trees/ |
(empty — ready) |
leetcode/
| File | Notes |
|---|---|
bsf.java |
BFS scratch |
recursion/CountGoodNumber.java |
Count good numbers |
recursion/pow.java |
Power function |
BST/morise_traversal/morisPreorder.java |
Morris preorder |
demo/
| File | Notes |
|---|---|
Main.java |
Entry point demo |
doublefdx.java |
Misc |
leetcode_496_3.java |
LC 496 solution |
tracelink/Client.java |
Tracelink client |
alpna plus library/amazon/easy/
| File | Problem |
|---|---|
mergeSort.java |
Merge sort |
reverseDuplicate.java |
Reverse duplicates |
DSA JAVA/
├── qustions/sorting/ — Sorting algorithms
├── Recursion/ — Recursion + hard problems
├── BinarySearch/ — Binary search
├── Hashing/ — Hashing basics
├── HashMap/ — HashMap problems
├── LinkedList/ — Linked list
├── 26Stack/ — Stack (impl + problems)
├── microsoft/ — Stock span (Microsoft)
├── Queue/ — Queue (impl + problems)
├── Heap/ — Heap / PriorityQueue
├── greedy/ — Greedy algorithms
├── BackTracking/ — Backtracking
├── BinaryTree/ — Binary tree basics
├── BinaryTree2/ — Binary tree advanced
├── BST1/ — BST basics
├── BST2/ — BST advanced
├── AVL Tree/ — AVL tree (placeholder)
├── Graphs/ — Graph algorithms
├── DP/ — Dynamic programming
├── Segment Tree/ — Segment tree
├── LastRun/Tree/ — Tree problems (recent)
├── LastRun2/BST/ — BST problems (recent)
├── LastRun2/Tree/ — Tree problems (recent)
├── LastRun3/BitManipulation/ — Bit manipulation
├── LastRun4/ — Permutations
├── LastRun5/Strings/ — String problems
├── LastRun6/Graph/ — Graph problems (recent)
├── LastRun7/ — Mixed (arrays, special series)
├── LastRun8_DP/ — DP problems (recent)
├── LastRun9_Hashing/ — Hashing (recent)
├── LastRun10_trie/ — Trie
├── LastRun_Stack/ — Stack (recent)
├── LastRun_greedy/ — Greedy (recent)
├── LastRun_linkedList/ — Linked list (recent)
├── LastRun_Senior_Staff_maths/— Senior-level math/strings
├── HackerRank/ — HackerRank solutions
├── leetcode/ — LeetCode scratch files
├── demo/ — Demo / entry points
└── alpna plus library/ — Amazon easy problems