Data Structures and Algorithms in Java
This repository is a collection of algorithms, data structures and coding challenges which I've solved over a period of time. The algorithms/solutions are implemented considering effecient Time and Space Complexity approaches. All the solutions are 100% correct and tested against various test cases, unless marked as TODO/InProgress.
This section contains implementation of different Data Structures in Java.
Data Structure | Implementation |
---|---|
Stack Methods Implemented: push(), pop(), peek(), isEmpty() |
View |
Queue Methods Implemented: offer(), poll(), peek(), isEmpty() |
View |
Linked List Methods Implemented: appendToTail(), add(), appendToHead(), removeFirst(), removeLast(), clone(), addAll(), reverseBetween(), getMid(), isPalindrome(), reverse(), toString(), mergeWith(), mergeTwoLists(), reverseInKGroups(), hasCycle(), removeKthFromEnd() |
View |
Tree Methods Implemented: preorderIterative(), inorderIterative(), levelOrder() ... many more |
View |
Graph Methods Implemented: BFS(), DFS(), Djikstras(), TopologicalSort() |
View |
Trie Methods Implemented: search(), print() |
View |
MaxHeap Methods Implemented: insert(), fetchTop(), doubleSize() |
View |
MinHeap Methods Implemented: insert(), fetchTop(), doubleSize() |
View |
HashMap Methods Implemented: put(), add(), containsKey(), remove() |
View |
SegmentTree Methods Implemented: query(), update() |
View |
CartesianTree Methods Implemented: buildCartesianTree() |
View |
BinaryIndexedTree Methods Implemented: build(), query(), queryRange() |
View |
Algorithms Problems Java
Problem | Description |
---|---|
Island Perimeter |
View |
Reshape Matrix |
View |
Next Greater Element 1 |
View |
Average of Levels in a Binary Tree |
View |
Judge Route Circle |
View |
Nim Game |
View |
Invert a Binary Tree |
View |
Two Sum 4 BST |
View |
Find the difference |
View |
Merge Two Binary Trees |
View |
Sum of 2 Integers |
View |
BinaryTree to String |
View |
Construct Rectangle |
View |
Distribute Candies |
View |
Convert BST to Greater Tree |
View |
Intersection of 2 Arrays |
View |
Minimum Absolute difference in BST |
View |
Ransome Note |
View |
Excelsheet Column Number |
View |
Assign Cookies |
View |
Binary Tree Tilt |
View |
Sum of left leaves |
View |
Minimum index sum of 2 lists |
View |
Majority Element |
View |
Relative Ranking |
View |
Delete Node |
View |
Contains Duplicate |
View |
Minimum moves to equal array |
View |
Longest Palindrome |
View |
Max product 3 nos |
View |
Student attendance record |
View |
Diameter of Binary Tree |
View |
Sorted array to BST |
View |
Longest Harmonic Subsequence Length |
View |
UglyNumber |
View |
Symmetric SubTree |
View |
PathSum III |
View |
Power Of 2 |
View |
House Robber I |
View |
Level Order Bottomup |
View |
Set Mismatch |
View |
Intersection Arrays |
View |
LongestIncreasingSubsequence |
View |
Power 4 |
View |
ReverseOfVowels |
View |
image Smoother |
View |
Perfect Square |
View |
Balanced Binary Tree |
View |
Arange Coins |
View |
Isomorphic String |
View |
Factorial Zeroes |
View |
Path Sum |
View |
Min Depth |
View |
WordPattern |
View |
Non Decreasing Array |
View |
PsychometricTesting |
View |
Sum Square Number |
View |
Length Of Last Word |
View |
Valid Palindrome II |
View |
ExcelSheetColumnTitle |
View |
PerfectNumber |
View |
FirstBadVersion |
View |
Can Place Flowers |
View |
Square Root |
View |
MaximumAverageSubarrayI |
View |
SwapNodesInPairs |
View |
Subsets I |
View |
Subsets II |
View |
Permutations |
View |
Permutations II |
View |
CombinationSum |
View |
ValidSquare |
View |
KEmptySlots |
View |
LongestAbsolutePath |
View |
LongestSubStringWithKDistinctChars |
View |
LicenseKeyFormatting |
View |
RangeSumQuery2DMutable |
View |
MovingAverage |
View |
BinaryTreeLongestConsecutiveSequence |
View |
SentenceScreenFitting |
View |
BombEnemy |
View |
ZigZagIterator |
View |
DecodeString |
View |
PalindromePairs |
View |
PowerSetSubStringsWithoutDups |
View |
PalindromicSubStrings |
View |
RepeatedStringMatch |
View |
ShortestDistanceFromAllBuildings |
View |
SkyLineProblem |
View |
MergeSortedArray |
View |
IntegerToEnglishWords |
View |
BattleShipsInABoard |
View |
LinkedListCycle |
View |
PopulatingNextRightPointersI |
View |
SearchInRotatedSortedArray |
View |
SpiralMatrixNoTouch |
View |
InorderSuccessorBST |
View |
SortColors |
View |
FindMinimumInRotatedSortedArray |
View |
AddTwoNumbersII |
View |
LowestCommonAncestorBST |
View |
ReverseWordsInStringII |
View |
MinimumPathSum |
View |
DungeonGame |
View |
SerializeAndDeserializeBinaryTree |
View |
MissingRanges |
View |
LongestConsecutiveSequence |
View |
ValidTriangleNumber |
View |
ContainerWithMostWater |
View |
BulbSwitcherI |
View |
SplitArrayWithEqualSum |
View |
FindTheCeleberity |
View |
CompareVersion |
View |
SummaryRanges |
View |
ThreeSumSmaller |
View |
CompareVersion |
View |
UTF_8Validation |
View |
ValidAbbrevation |
View |
StrobographicNumberII |
View |
BSTIterator |
View |
MergeIntervals |
View |
FlattenNestedListIterator |
View |
EncodeAndDecodeStrings |
View |
QueueReconstructionByHeight.java |
View |
LongestSubstringWithAtMost2DistinctChars |
View |
ConstructBinaryTreeFromInorderAndPostOrderTraversal |
View |
ConstructBinaryTreeFromInorderAndPreOrderTraversal |
View |
RangeAddition |
View |
ClimbStairs |
View |
SimplifyPath |
View |
StrobogrammaticNumber |
View |
WiggleSort |
View |
BinaryTreeVerticalOrderTraversal |
View |
TrapRainWater |
View |
NthDigit |
View |
MaximumProductSubarray |
View |
IsSubSequence |
View |
RangeSumQueryImmutable |
View |
PaintHouse |
View |
EditDistance |
View |
LargestRectangleInHistogram |
View |
ShortestUnsortedContinuousSubarray |
View |
MaximalRectangle |
View |
PerfectSquares |
View |
DoubeCheckedSynchronizationSingleton |
View |
BurstBalloons |
View |
CoinChange |
View |
DecodeWays |
View |
BestTimeToBuyAndSellStock |
View |
BestTimeToBuyAndSellStockWithCooldown |
View |
UglyNumberII |
View |
IntegerBreak |
View |
WildCardMatching |
View |
DistinctSubsequence |
View |
InterleavingString |
View |
WordSearch |
View |
SudokuSolver |
View |
NQueens |
View |
NQueensII |
View |
Combinations |
View |
RestoreIpAddresses |
View |
LongestIncreasingPathInMatrix |
View |
JumpGame |
View |
SearchForRange |
View |
PeekingIterator |
View |
LongestWordInDictionaryViaDeleting |
View |
GCD |
View |
ExtendedEuclideanAlgorithm |
View |
WaterJugProblem |
View |
NextPermutation |
View |
MaximumVacationDays |
View |
LongestIncreasingSubSequence |
View |
PaintFence |
View |
LongestCommonSubsequence |
View |
MinimumInsertionForPalindrome |
View |
PowerOfThree |
View |
SubstringWithConcatenationOfWords |
View |
CombinationSumII |
View |
StringCompression |
View |
SegmentTree_RangeSum |
View |
SegmentTree_RangeMin |
View |
CountSmallerNumberAfterSelf |
View |
RangeSumQuery |
View |
MaximumBinaryTree |
View |
LargestBSTSubtree |
View |
HouseRobberII |
View |
CombinationSumII |
View |
TwoKeysKeyboard |
View |
MovieRating |
View |
ContigousSubarraysWithZeroSum |
View |
KStringSizeWith1CharRepeating2ce |
View |
FindSegementSize |
View |
UniqueBinarySearchTrees |
View |
UniqueBinarySearchTreesII |
View |
RussianDollEnvelopes |
View |
MedianTwoSortedArrays |
View |
LonelyPixelI |
View |
LonelyPixelII |
View |
KDiffPairsArray |
View |
TwoSumII |
View |
MultiplyStrings |
View |
PlusOne |
View |
ReverseBits |
View |
DetectCapital |
View |
FindLargestValueEachTreeRow |
View |
HappyNumber |
View |
AddBinary |
View |
MoveZeroes |
View |
PalindromeNumbers |
View |
NumberToBase |
View |
StrStr |
View |
LeastFrequentlyUsed |
View |
LeastRecentlyUsed |
View |
FirstUniqueCharacter |
View |
ZigZagConversion |
View |
FirstMissingPositive |
View |
FindDuplicateNumber |
View |
ProductArrayExceptSelf |
View |
LongestPalindromicSubstring |
View |
ReverseInteger |
View |
ReverseInteger |
View |
StringToInteger |
View |
ValidParanthesis |
View |
SurroundedRegions |
View |
CountingBits |
View |
FindDisappearedNumber |
View |
ThreeSum |
View |
LetterCombinationsOfPhoneNumber |
View |
GroupAnagrams |
View |
ValidAnagram |
View |
PascalsTriangleII |
View |
ThirdMaximumNumber |
View |
RegularExpressionMatching |
View |
SortByFrequency |
View |
LongestSubstringWithAtleastKRepeatingChars |
View |
GrayCode |
View |
RotateFunction |
View |
RepeatedSubstringPattern |
View |
NumberOfIslands |
View |
LongestPalindromicSubsequence |
View |
WordBreak |
View |
WordLadder |
View |
WordLadderII |
View |
WordBreakII |
View |
JewelsAndStones |
View |
UniqueEmailAddresses |
View |
FindAnagramMappings |
View |
FlippingAnImage |
View |
PeakIndexInAMountainArray |
View |
RecentCounter |
View |
DeleteColumnsToMakeSorted |
View |
LoggerRateLimiter |
View |
LeafSimilarTrees |
View |
BinaryTreeLevelOrderConstantSpace |
View |
MinimumAreaRectangle |
View |
MinimumAreaRectangleII |
View |
PatchingArray |
View |
QuickFind |
View |
QuickUnion |
View |
NRepeatedElementInSize2NArray |
View |
RangeMinimumQuery |
View |
EulerTour |
View |
EulerTourGraph |
View |
ReversePairs |
View |
BinarySearch |
View |
FindSmallestLetterGreaterThanTarget |
View |
ClosestBinarySearchTreeValue |
View |
Heaters |
View |
SearchInASortedArrayOfUnknownSize |
View |
SearchInsertPosition |
View |
TwoSum |
View |
MaxIncreaseToKeepCitySkyline |
View |
ContinuousSubarraySum |
View |
LemonadeChange |
View |
StringWithoutAAAOrBBB |
View |
MinimumAddToMakeParenthesesValid |
View |
ScoreAfterFlippingMatrix |
View |
PartitionLabels |
View |
PalindromePartitioning |
View |
CombinationSumIII |
View |
MinimumNumberOfRefuelingStops |
View |
PalindromePartitioningII |
View |
PalindromePermutation |
View |
PalindromePermutationII |
View |
KClosestPointsToOrigin |
View |
BoyerMoore |
View |
ConvertBinarySearchTreeToSortedDoublyLinkedList |
View |
BeautifulArray |
View |
LinkedListRandomNode |
View |
RandomPickIndex |
View |
SurfaceAreaOf3DShapes |
View |
FlipGameII |
View |
MaximumDepthOfNaryTree |
View |
NaryTreeLevelOrderTraversal |
View |
EmployeeImportance |
View |
CousinsInBinaryTree |
View |
IncreasingOrderSearchTree |
View |
DistributeCoinsInBinaryTree |
View |
KeysAndRooms |
View |
NumberOfConnectedComponentsInAnUndirectedGraph |
View |
CloneGraph |
View |
WeightedQuickUnionPathCompression |
View |
RedundantConnection |
View |
MinimumDistanceBetweenBSTNodes |
View |
RangeSumOfBST |
View |
SplitBST |
View |
MyCalendarI |
View |
ImplementRand10UsingRand7 |
View |
HandOfStraights |
View |
CourseSchedule |
View |
CourseScheduleII |
View |
CoinChangeII |
View |
MinimumSizeSubarraySum |
View |
RemoveKDigits |
View |
Find132pattern |
View |
EvaluateReversePolishNotation |
View |
AsteroidCollision |
View |
VerifyPreorderSequenceInBinarySearchTree |
View |
Misc
DP 0: reduce the problem to finite state machine 1: reduce the fsm to graph 2: reduce graph to logical graph 3: traverse this graph with keeping constraints