Leetcode solutions in Java
My accepted leetcode solutions to some of the common interview problems.
Array
- Pascals Traiangle II (Easy)
- Product Of Array Except Self (Medium)
- Rotate Matrix (Medium)
- Set Matrix Zeroes (Medium)
- Third Maximum Number (Easy)
- Two Sum (Easy)
- TwoSum II (Easy)
- Can Place Flowers (Easy)
- Merge Intervals (Medium)
- First Missing Positive (Hard)
- Fruit Into Baskets (Medium)
- MaxProduct Of Three Numbers (Easy)
- Missing Number (Easy)
- Merge Sorted Array (Easy)
- Rotate Array (Easy)
- Sort Colors (Medium)
- Battleships in a Board (Medium)
- Find the Celebrity (Medium)
- Meeting Rooms (Easy)
- Longest Continuous Increasing Subsequence (Easy)
- Sparse Matrix Multiplication (Medium)
- Read N Characters Given Read4 (Easy)
- Maximum Swap (Medium)
- H-Index (Medium)
- Insert Interval (Hard)
- Increasing Triplet Subsequence (Medium)
- K Empty Slots (Hard)
- Subarray Sum Equals K (Medium)
- Pour Water (Medium)
- Relative Ranks (Easy)
- Next Greater Element I (Easy)
- Largest Number At Least Twice of Others (Easy)
- Minimum Moves to Equal Array Elements II (Median)
- Image Smoother (Easy)
- Minimum Index Sum of Two Lists (Easy)
- Card Flipping Game (Medium)
- Employee Free Time (Hard)
- Best Meeting Point (Hard)
- My Calendar III (Hard)
- Champagne Tower (Medium)
- Valid Tic-Tac-Toe State (Medium)
- Number of Subarrays with Bounded Maximum (Medium)
- Surface Area of 3D Shapes (Easy)
- Max Consecutive Ones (Easy)
- Max Consecutive Ones II (Medium)
- Add to Array-Form of Integer (Easy)
- Find Pivot Index (Easy)
- Largest Time for Given Digits (Easy)
- Minimum Time Difference (Medium)
- Reveal Cards In Increasing Order (Medium)
- Sort Array By Parity II (Easy)
- Matrix Cells in Distance Order (Easy)
- Maximum Sum of Two Non-Overlapping Subarrays (Medium)
- Longest Line of Consecutive One in Matrix (Medium)
- Array Partition I (Easy)
- Relative Sort Array (Easy)
- Meeting Scheduler (Medium)
- Minimum Swaps to Group All 1's Together (Medium)
- Array Nesting (Medium)
Backtracking
- Combinations (Medium)
- Combinations Sum (Medium)
- Combinations Sum II (Medium)
- Letter Phone Number (Medium)
- Paliandrome Partitioning (Medium)
- Permutations (Medium)
- Permutations II (Medium)
- SubSets (Medium)
- SubSet II (Medium)
- Word Search (Medium)
- Word Search II (Hard)
- Generate Parentheses (Medium)
- Remove Invalid Parentheses (Hard)
- Regular Expression Matching (Hard)
- Expression Add Operators (Hard)
- Wildcard Matching (Hard)
- Letter Case Permutation (Easy)
- Zuma Game (Hard)
- Matchsticks to Square (Medium)
Binary Search
- Minimum Sorted Rotated Array (Medium)
- Search in a Rotated Sorted Array (Medium)
- Search for a Range (Medium)
- Sqrt(x) (Easy)
- Search Insert Position (Easy)
- Median of Two Sorted Arrays (Hard)
- Pow(x, n) (Medium)
- Find Peak Element (Medium)
- Target Sum (Medium)
- H-Index II (Medium)
- Swim in Rising Water (Hard)
- Time Based Key-Value Store (Medium)
- Minimum Window Subsequence (Hard)
- Koko Eating Bananas (Hard)
- Single Element in a Sorted Array (Medium)
Bit Manipulation
- Gray Code (Medium)
- Hamming Distance (Easy)
- Total Hamming Distance (Medium)
- Divide Two Integers (Medium)
- Binary Number with Alternating Bits (Easy)
- Binary Watch (Easy)
Breadth First Search
- Binaray Tree Level Order Traversal (Medium)
- Word Ladder (Medium)
- Word Ladder II (Hard)
- Walls and Gates (Medium)
- Open the lock (Medium)
- Cut Off Trees for Golf Event (Hard)
- Race Car (Hard)
- Bus Routes (Hard)
- Sliding Puzzle (Hard)
- Matrix (Medium)
- Rotting Oranges (Medium)
Depth First Search
- Minesweeper (Medium)
- Movie Recommend (Medium)
- Number Of Islands (Medium)
- Course Schedule (Medium)
- Course Schedule II (Medium)
- Alien Dictionary (Hard)
- Graph Valid Tree (Medium)
- Longest Consecutive Sequence (Hard)
- Accounts Merge (Medium)
- CloneGraph (Medium)
- Island Perimeter (Easy)
- Number of Distinct Islands (Medium)
- Number of Distinct Islands II (Hard)
- Smallest Rectangle Enclosing Black Pixels (Hard)
- Bricks Falling When Hit (Hard)
- Robot Room Cleaner (Hard)
- Cracking the Safe (Hard)
- All Paths From Source to Target (Medium)
- Max Area of Island (Medium)
- Satisfiability of Equality Equations (Medium)
- Number of Enclaves (Medium)
- As Far from Land as Possible (Medium)
- Minimize Malware Spread (Hard)
- Parallel Courses (Hard)
- Connecting Cities With Minimum Cost (Medium)
- Critical Connections in a Network (Hard)
Design
- Copy List With Random Pointer (Medium)
- Encode and Decode Tiny URL (Medium)
- LFU Cache (Hard)
- LRU Cache (Hard)
- Insert Delete Get Random (Medium)
- Serialize Deserialize Binary Tree (Hard)
- Design Twitter (Medium)
- Tic-Tac-Toe (Medium)
- Implement Trie (Prefix Tree) (Medium)
- Binary Search Tree Iterator (Medium)
- Design Search Autocomplete System (Hard)
- Design Excel Sum Formula (Hard)
- Flatten Nested List Iterator (Medium)
- Add and Search Word - Data structure design (Medium)
- Prefix and Suffix Search (Hard)
- Insert Delete GetRandom O(1) - Duplicates allowed (Hard)
Divide and Conquer
- Kth Largest Element In a Array (Medium)
- Reverse Pairs (Hard)
- Search in a 2D Matrix (Medium)
- 24 Game (Hard)
- Reverse Pairs II (Hard)
- My Calendar II (Medium)
Dynamic Programming
- Best Time To Buy and Sell Stocks (Easy)
- Best Time to Buy and Sell Stock III (Hard)
- Best Time to Buy and Sell Stock with Transaction Fee (Medium)
- Climbing Stairs (Easy)
- Coin Change (Medium)
- Coin Change 2 (Medium)
- Decode Ways (Medium)
- House Robber (Easy)
- House Robber II (Medium)
- Longest Increasing Subsequence (Medium)
- Longest Paliandromic Substring (Medium)
- Longest Palindromic Subsequence (Medium)
- Maximum Product Subarray (Medium)
- Min Cost Climbing Stairs (Easy)
- Palindrome Partitioning II (Hard)
- UniqueBinary Search Trees (Medium)
- Unique Binary Search Trees II (Medium)
- WordBreak (Medium)
- WordBreak II (Hard)
- Concatenated Words (Hard)
- Can I Win (Medium)
- Maximum Subarray (Easy)
- Dungeon Game (Hard)
- 2 Keys Keyboard (Medium)
- Maximum Sum of 3 Non-Overlapping Subarrays (Hard)
- Maximal Square (Medium)
- Continuous Subarray Sum (Medium)
- Decode Ways II (Hard)
- Palindromic Substrings (Medium)
- Number of Longest Increasing Subsequence (Medium)
- Combination Sum IV (Medium)
- Paint House II (Hard)
- Split Array Largest Sum (Hard)
- Number Of Corner Rectangles (Medium)
- Burst Balloons (Hard)
- Largest Plus Sign (Medium)
- Palindrome Pairs (Hard)
- Cherry Pickup (Hard)
- Knight Probability in Chessboard (Medium)
- Largest Sum of Averages (Medium)
- Minimum Number of Refueling Stops (Hard)
- Cat and Mouse (Hard)
- Stone Game (Medium)
- Odd Even Jump (Hard)
- Profitable Schemes (Hard)
- Maximum Vacation Days (Hard)
- Russian Doll Envelopes (Hard)
- Student Attendance Record II (Hard)
- Out of Boundary Paths (Medium)
- Remove Boxes (Hard)
- Stickers to Spell Word (Hard)
- Ones and Zeroes (Medium)
- Encode String with Shortest Length (Hard)
- Length of Longest Fibonacci Subsequence (Medium)
- Make Array Strictly Increasing (Hard)
- Minimum Number of Taps to Open to Water a Garden (Hard)
- Delete Columns to Make Sorted III (Hard)
- Handshakes That Don't Cross (Hard)
- Minimum Difficulty of a Job Schedule (Hard)
- Jump Game V (Hard)
- Freedom Trail (Hard)
- Strange Printer (Hard)
- Minimum Cost to Merge Stones (Hard)
- Interleaving String (Hard)
- Count Vowels Permutation (Hard)
- Non-negative Integers without Consecutive Ones (Hard)
- Bomb Enemy (Medium)
- Number of Dice Rolls With Target Sum (Medium)
- Distinct Subsequences (Hard)
- Distinct Subsequences II (Hard)
- Minimum Distance to Type a Word Using Two Fingers (Hard)
- Valid Palindrome III (Hard)
- Palindrome Partitioning III (Hard)
- Tiling a Rectangle with the Fewest Squares (Hard)
- Longest Chunked Palindrome Decomposition (Hard)
- Stone Game III (Hard)
- Number of Ways to Stay in the Same Place After Some Steps (Hard)
- Toss Strange Coins (Medium)
- Knight Dialer (Medium)
- Palindrome Removal (Hard)
- Restore The Array (Hard)
- Cherry Pickup II (Hard)
- Constrained Subsequence Sum (Hard)
- Largest Multiple of Three (Hard)
- Largest Multiple of Three (Hard)
- Number of Music Playlists (Hard)
- Paint House III (Hard)
- Shortest Path Visiting All Nodes (Hard)
- Smallest Sufficient Team (Hard)
- Stone Game IV (Hard)
- Tallest Billboard (Hard)
- Count Different Palindromic Subsequences (Hard)
- Number of Paths with Max Score (Hard)
Greedy
- Jump Game (Medium)
- Jump Game II (Hard)
- Course Schedule III (Medium)
- GasStation (Medium)
- Non-Overlapping Intervals (Medium)
- Minimum Number of Arrows to Burst Balloons (Medium)
- Queue Reconstruction By Height (Medium)
- Task Scheduler (Medium)
- Maximum Length of Pair Chain (Medium)
- Lemonade Change (Easy)
- Score After Flipping Matrix (Medium)
- IPO (Hard)
- String Without AAA or BBB (Medium)
- Boats to Save People (Medium)
- Broken Calculator (Medium)
- Two City Scheduling (Easy)
- Minimum Time to Build Blocks (Hard)
- Reducing Dishes (Hard)
Hashing
- Anagrams (Medium)
- Group Anagrams (Medium)
- Kdiff Pairs In a Array (Easy)
- Sort Character by Frequency (Medium)
- Two Sum (Easy)
- Valid Anagram (Easy)
- Maximum Size Subarray Sum Equals k (Medium)
- Contiguous Array (Medium)
- Brick Wall (Medium)
- Partition Labels (Medium)
- Custom Sort String (Medium)
- Short Encoding of Words (Medium)
- Substring with Concatenation of All Words (Hard)
- Distribute Candies (Easy)
- Groups of Special-Equivalent Strings (Easy)
- Number of Atoms (Hard)
- Analyze User Website Visit Pattern (Medium)
- String Transforms Into Another String (Hard)
Heap
- Sliding Window Maximum (Hard)
- The Skyline Problem (Hard)
- Meeting Rooms II (Medium)
- Top K Frequent Words (Medium)
- Candy (Hard)
- Smallest Rotation with Highest Score (Hard)
- Maximum Frequency Stack (Hard)
- Reachable Nodes In Subdivided Graph (Hard)
- K Closest Points to Origin (Medium)
- Distant Barcodes (Medium)
Linked List
- Intersection of two Linked-Lists (Easy)
- Linked List Cycle (Easy)
- Merge K Sorted Lists (Hard)
- Merge Two Sorted List (Easy)
- Paliandrome List (Easy)
- Reverse Linked List (Easy)
- Delete Node in a Linked List (Easy)
- Reverse Nodes in k-Group (Hard)
- Swap Nodes in Pairs (Medium)
- Middle of Linked List (Easy)
- Split Linked List in Parts (Medium)
- Next Greater Node In Linked List (Medium)
Math
- Add Two Numbers (Medium)
- Count Primes (Easy)
- Rotate Function (Medium)
- Water and Jug Problem (Medium)
- Add Digits (Easy)
- Excel Sheet Column Title (Easy)
- Roman to Integer (Easy)
- Bulb Switcher II (Medium)
- Global and Local Inversions (Medium)
- Solve the Equation (Medium)
- Couples Holding Hands (Hard)
- Reaching Points (Hard)
- Nth Magical Number (Hard)
- Squirrel Simulation (Medium)
- Projection Area of 3D Shapes (Easy)
- Decoded String at Index (Medium)
- Base 7 (Easy)
- Smallest Range I (Easy)
- Largest Component Size by Common Factor (Hard)
- Super Washing Machines (Hard)
- Rectangle Overlap (Easy)
- Nth Digit (Easy)
Reservoir Sampling
- Random Pick Index (Medium)
Stack
- Min Stack (Easy)
- Valid Parentheses (Easy)
- Largest Rectangle In Histogram (Hard)
- Implement Queue using Stacks (Easy)
- Maximal Rectangle (Hard)
- Exclusive Time of Functions (Medium)
- Basic Calculator (Hard)
- Decode String (Medium)
- Longest Valid Parentheses (Hard)
String
- First Unique Character In a String (Easy)
- Repeated Substring Pattern (Easy)
- Reverse Words In a String (Medium)
- ReverseWords II (Medium)
- String to Integer (Medium)
- Text Justification (Hard)
- ZigZag Conversion (Medium)
- Implement StrStr (Easy)
- Excel Sheet Column Number (Easy)
- Compare Version Numbers (Easy)
- Valid Palindrome (Easy)
- Simplify Path (Medium)
- Permutation in String (Medium)
- Add Binary (Easy)
- Valid Palindrome II (Easy)
- One Edit Distance (Medium)
- Count and Say (Easy)
- Multiply Strings (Medium)
- Longest Word in Dictionary through Deleting (Medium)
- Isomorphic Strings (Easy)
- String Compression (Easy)
- Longest Common Prefix (Easy)
- Find the Closest Palindrome (Hard)
- Monotone Increasing Digits (Medium)
- Shortest Palindrome (Hard)
- Valid Word Abbreviation (Easy)
- Longest Palindrome (Easy)
- Replace Words (Medium)
- Rotate String (Easy)
- Keyboard Row (Easy)
- Student Attendance Record I (Easy)
- Split Concatenated Strings (Medium)
- Valid Word Square (Easy)
- Reconstruct Original Digits from English (Medium)
- Push Dominoes (Medium)
- Validate IP Address (Medium)
- Reverse String II (Easy)
- Find Words That Can Be Formed by Characters (Easy)
- Minimum Add to Make Parentheses Valid (Medium)
Tree
- Binaray Tree Right Side View (Medium)
- Binary Tree Maximum Path Sum (Hard)
- Boundary of Binary Tree (Medium)
- Convert sorted array to BST (Medium)
- Lowest Common Ancestor of a Binary Tree (Medium)
- Lowest Common Ancestor of a BST (Easy)
- Most Frequent Subtree Sum (Medium)
- Path Sum III (Easy)
- Convert Postorder and Inorder traversal to Binary Tree (Medium)
- Convert Preorder and Inorder traversal to Binary Tree (Medium)
- Sorted Array to BST (Medium)
- Valid Binary Search Tree (Medium)
- Largest BST Subtree (Medium)
- Closest Binary Search Tree Value (Easy)
- Inorder Successor in BST (Medium)
- Construct String From Binary Tree (Easy)
- Flatten Binary Tree to Linked List (Medium)
- Populating Next Right Pointers in Each Node (Medium)
- Populating Next Right Pointers in Each Node II (Medium)
- Subtree of Another Tree (Easy)
- Binary Tree Zigzag Level Order Traversal (Medium)
- Binary Tree Inorder Traversal (Medium)
- Symmetric Tree (Easy)
- Maximum Binary Tree (Medium)
- Find Bottom Left Tree Value (Medium)
- Diameter of Binary Tree (Easy)
- Binary Tree Paths (Easy)
- Sum of Left Leaves (Easy)
- Two Sum IV - Input is a BST (Easy)
- Average of Levels in Binary Tree (Easy)
- Convert Binary Search Tree to Sorted Doubly Linked List (Easy)
- Same Tree (Easy)
- Binary Tree Longest Consecutive SequencefindMinDifference II (Medium)
- Minimum Absolute Difference in BST (Medium)
- Equal Tree Partition (Medium)
- Split BST (Medium)
- Closest Leaf in a Binary Tree (Medium)
- Maximum Width of Binary Tree (Medium)
- Recover Binary Search Tree (Hard)
- Binary Tree Postorder Traversal (Hard)
- Serialize and Deserialize N-ary Tree (Hard)
- Convert BST to Greater Tree (Easy)
- All Nodes Distance K in Binary Tree (Medium)
- All Possible Full Binary Trees (Medium)
- Flip Equivalent Binary Trees (Medium)
- Construct Binary Tree from String (Medium)
- Find Largest Value in Each Tree Row (Medium)
- Find Bottom Left Tree Value (Medium)
- Maximum Level Sum of a Binary Tree (Medium)
- Leaf-Similar Trees (Easy)
- Binary Tree Tilt (Easy)
Two Pointers
- Four Sum (Medium)
- Longest Substring Witout Repeats (Medium)
- Three Sum (Medium)
- Trapping Rain Water (Hard)
- 3Sum Closest (Medium)
- Move Zeroes (Easy)
- Remove Duplicates (Easy)
- Remove Duplicates II (Medium)
- Minimum Size Subarray Sum (Medium)
- Minimum Window Substring (Hard)
- Smallest Range (Hard)
- Subarray Product Less Than K (Medium)
- Number of Matching Subsequences (Medium)
- Subarrays with K Different Integers (Hard)
- Last Substring in Lexicographical Order (Hard)