This respository is a collection of readable and clean implementation of data structures and algorithms in JAVA. This is a work in progress, so some algorithms may not be included. You can find the optimised solution to 500+ popular problems from Leetcode, Geeksforgeeks, Interviewbit etc. If you have any questions, requests, or find any error in the provided solutions, please don't hesitate to contact me (my contact information is at the bottom of this file). If you find this repository helpful, I would like to know :)
-
- Lowercase
- Change string cases
- Shortest way to form string
- Reorganize string
- License key formatting
- Unique email addresses
- Longest string chain
- Longest word in sentence
- Longest word in dictionary
- Longest substring without repeating characters
- Longest common prefix
- Valid anagram
- Form anagrams with minimum steps
- Group anagrams
- Valid palindrome
- Valid alindrome remove atleast one character
- Shortest palindrome
- Palindromic substrings
- Palindromic substrings length greater than 1
- Palindromic substrings length greater than 2
- Distinct palindromic substrings
- Longest palindrome
- Longest palindromic substring
- Palindrome permutation
- Add strings
- Multiply strings
- Find the difference
- Most common words
- Match word pattern
- String compression
- Flip game
- Detect Capital
- Word Break
-
- Valid parentheses
- Minimum remove to make valid parentheses
- Minimum add to make valid parentheses
- Longest valid parentheses
- Score of parentheses
- Validate stack sequences
- Backspace string compare
- Evaluate reverse polish notation
- Sum of subarray minimums
- Simplify path
- Delete middle element of stack
- Remove duplicate letters
- Remove all adjacent duplicates
- Remove all k adjacent duplicates
- Daily temperatures
- Array burst problem
- Online stock span
- Nearest greater left
- Nearest greater right
- Nearest greater right circular array
- Nearest smaller left
- Nearest smaller right
- Next greater element
- Next greater element circular array
- Largest rectangle in histogram
-
- Linear Search
- Binary Search
-
- Find all anagrams in a string
- Longest k unique characters substring
- Longest continuous subarray with absolute diff less than or equal to limit
- Longest substring with at least k repeating characters
- Longest substring with at most k distinct characters
- Longest substring with at most two distinct characters
- Longest substring without repeating characters
- Maximum sum subarray of size
- Maximum number of vowels in a substring of given length
- Maximum of all subarrays of size k
- Subarray with sum S
- Minimum size subarray sum S
- Minimum size subarray greater or equal to sum S
- Minimum number of k consecutive bit flips
- Minimum operations to reduce x to zero
- Minimum window subsequence
- Minimum window substring
- Permutation in string
- Repeated DNA sequences
- Sliding window median
- Subarray with given sum
- Subarrays with k different integers
- First negative integer in every window of size k
- Count number of nice subarray
- Fruit into baskets
-
- Delete node
- Reverse linkedlist
- Swap nodes in pairs
- Odd-Even nodes
- Detect loop
- Find start of loop
- Remove duplicates
- Remove nth node from end
- Sort list with Insertion Sort
- Sort list with Heap Sort
- Sort list with Merge Sort
- Merge 2 sorted linkedlist
- Merge k sorted linkedlist
- Insert into sorted linkedlist
- Add 2 numbers
- Add 2 polynomials
-
- Binary Tree Traversal
- Binary Tree View
- Balance Binary Tree
- Symmetric Trees
- Same Binary Trees
- Leaf Similar Trees
- Subtree of another Tree
- Cousins Nodes
- Merge Binary Trees
- Invert Binary Tree
- Tilt Binary Tree
- Diameter of Binary Tree
- Minimum Depth
- Maximum Depth
- Maximum Height
- Maximum Level Sum
- Maximum Path Sum
- Binary Search Tree
-
- Graph Traversal
- Shortest Path
- BFS
- Dijkstra's Algorithm
- Bellman-Ford
- Floyd-Warshall
- Johnson's Algorithm
- Minimum Spanning Tree
- Kruskal's Algorithm
- Prim's Algorithm
- Tarjan's Algorithm
- Topological Sort
- Detect Cycle
- Connected Components
- Strongly Connected Components
- Bipartite Graph
-
- k closest elements
- k closest points to origin
- k largest elements with max heap
- k largest element with min heap
- k pairs with smallest sums
- k top frequent elements
- k top frequent words
- k weakest rows in a matrix
- kth largest element in a stream
- kth largest element in a array
- kth largest sum in continuius subarray
- kth smallest element in a array
- Sort a k sorted array
- Sort array by increasing frequency
- Sort characters by frequency
- Largest values from labels
- Minimum cost of ropes
- Minimum cost to connect sticks
- Sliding window median
- Find median from data stream
-
Divides the problem into smaller parts and then solve those parts
-
Chooses the best option at the current time, without any consideration for the future
- Jump Game -Dijkstra's Algorithm
- Kruskal's Algorithm
- Prim's Algorithm
- Circular Gas Station
- Partition Labels
-
Builds solution using previously found sub-solutions
- Fibonacci Series
- Climbing Stairs
- Decode Ways
- 0/1 Knapsack
- Longest Increasing Subsequence
- Russian Doll Envelopes
- Longest Common Subsequence
- Shortest Common Supersequence
- Longest Common Substring
- Longest Common Palindromic Subsequence
- Longest Common Palindromic Substring
- Longest Repeating Subsequence
- Longest Repeating Substring
- Longest Valid Parentheses
- Edit (Levenshtein) Distance
- Subset Sum
- Matrix Chain Multiplication
- Burst Balloons
- Unbounded Knapsack
- Coin Change-No. of Ways
- Coin Change-No. of Coins
- Rod Cutting Problem
- Egg Dropping Problem
- Boolean Parenthesization
- Scramble String
- Bellman-Ford
- Floyd-Warshall
- Unique BST
-
Similar to brute force, try to generate all possible solutions, but each time you generate next solution you test if it satisfies all conditions, and only then continue generating subsequent solutions. Otherwise, backtrack, and go on a different path of finding a solution.
Farheen Bano - [email protected]
This repository is released under the MIT license. In short, this means you are free to use this software in any personal, open-source or commercial projects. Attribution is optional but appreciated.
Consider donating to support my creation of educational content: