Skip to content

Latest commit

 

History

History
428 lines (378 loc) · 307 KB

README.md

File metadata and controls

428 lines (378 loc) · 307 KB

Leetcode solutions for 🚀 NeetCode.io

This repo hosts the solutions found on NeetCode.io including the solutions shown on the NeetCode YouTube channel. The site will periodically be updated with new solutions from this repo!


Solutions from these languages will be linked from NeetCode.io:

Python, Java, JavaScript, C++, Go, Swift, C#, TypeScript, Rust, Kotlin, Ruby, C, Scala and Dart

Solutions are also welcome for any other supported language on leetcode.com!

Contributing

Please read the contributing guidlines before opening a PR

To contribute, please fork this repo and open a PR adding a missing solution from the supported languages.

If you would like to have collaborator permissions on the repo to merge your own PRs or review others' PRs please let me know.

Credits

Missing Solutions

Arrays & Hashing

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0217 - Contains Duplicate
0242 - Valid Anagram
1299 - Replace Elements With Greatest Element On Right Side
0392 - Is Subsequence
0058 - Length of Last Word
0001 - Two Sum
0014 - Longest Common Prefix
0049 - Group Anagrams
0118 - Pascals Triangle
0027 - Remove Element
0929 - Unique Email Addresses
0205 - Isomorphic Strings
0605 - Can Place Flowers
0169 - Majority Element
0496 - Next Greater Element I
0724 - Find Pivot Index
0448 - Find All Numbers Disappeared In An Array
1189 - Maximum Number of Balloons
0290 - Word Pattern
0347 - Top K Frequent Elements
0238 - Product of Array Except Self
0036 - Valid Sudoku
0271 - Encode And Decode Strings
0128 - Longest Consecutive Sequence
0075 - Sort Colors
0535 - Encode And Decode Tinyurl
0554 - Brick Wall
0122 - Best Time to Buy And Sell Stock II
0560 - Subarray Sum Equals K
1930 - Unique Length 3 Palindromic Subsequences
1963 - Minimum Number of Swaps to Make The String Balanced
2001 - Number of Pairs of Interchangeable Rectangles
2002 - Maximum Product of The Length of Two Palindromic Subsequences
2017 - Grid Game
0438 - Find All Anagrams In a String
0028 - Find The Index of The First Occurrence In a String
0280 - Wiggle Sort
0179 - Largest Number
0523 - Continuous Subarray Sum
0838 - Push Dominoes
0187 - Repeated Dna Sequences
0380 - Insert Delete Get Random O(1)
1461 - Check if a String Contains All Binary Codes of Size K
0304 - Range Sum Query 2D Immutable
0665 - Non Decreasing Array
0041 - First Missing Positive

Two Pointers

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0125 - Valid Palindrome
0680 - Valid Palindrome II
1984 - Minimum Difference Between Highest And Lowest of K Scores
0344 - Reverse String
0088 - Merge Sorted Array
0283 - Move Zeroes
0026 - Remove Duplicates From Sorted Array
0167 - Two Sum II Input Array Is Sorted
0015 - 3Sum
0018 - 4Sum
0011 - Container With Most Water
1498 - Number of Subsequences That Satisfy The Given Sum Condition
0189 - Rotate Array
1968 - Array With Elements Not Equal to Average of Neighbors
0881 - Boats to Save People
0042 - Trapping Rain Water

Sliding Window

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0121 - Best Time to Buy And Sell Stock
0003 - Longest Substring Without Repeating Characters
0424 - Longest Repeating Character Replacement
0567 - Permutation In String
1838 - Frequency of The Most Frequent Element
1888 - Minimum Number of Flips to Make The Binary String Alternating
0209 - Minimum Size Subarray Sum
0658 - Find K Closest Elements
0076 - Minimum Window Substring
0239 - Sliding Window Maximum

Stack

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0020 - Valid Parentheses
0682 - Baseball Game
0225 - Implement Stack Using Queues
0155 - Min Stack
0150 - Evaluate Reverse Polish Notation
0022 - Generate Parentheses
0735 - Asteroid Collision
0739 - Daily Temperatures
0901 - Online Stock Span
0853 - Car Fleet
0071 - Simplify Path
0394 - Decode String
0402 - Remove K Digits
1209 - Remove All Adjacent Duplicates In String II
0132 - 132 Pattern
0895 - Maximum Frequency Stack
0084 - Largest Rectangle In Histogram

Binary Search

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0704 - Binary Search
0035 - Search Insert Position
0374 - Guess Number Higher Or Lower
0441 - Arranging Coins
0977 - Squares of a Sorted Array
0367 - Valid Perfect Square
0074 - Search a 2D Matrix
0875 - Koko Eating Bananas
0033 - Search In Rotated Sorted Array
0153 - Find Minimum In Rotated Sorted Array
0981 - Time Based Key Value Store
0034 - Find First And Last Position of Element In Sorted Array
1898 - Maximum Number of Removable Characters
0116 - Populating Next Right Pointers In Each Node
1268 - Search Suggestions System
0410 - Split Array Largest Sum
0004 - Median of Two Sorted Arrays

Linked List

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0206 - Reverse Linked List
0021 - Merge Two Sorted Lists
0234 - Palindrome Linked List
0203 - Remove Linked List Elements
0083 - Remove Duplicates From Sorted List
0160 - Intersection of Two Linked Lists
0143 - Reorder List
0019 - Remove Nth Node From End of List
0138 - Copy List With Random Pointer
0707 - Design Linked List
1472 - Design Browser History
0002 - Add Two Numbers
0141 - Linked List Cycle
0287 - Find The Duplicate Number
0024 - Swap Nodes In Pairs
0148 - Sort List
0086 - Partition List
0061 - Rotate List
0092 - Reverse Linked List II
0622 - Design Circular Queue
0147 - Insertion Sort List
0146 - LRU Cache
0023 - Merge K Sorted Lists
0025 - Reverse Nodes In K Group

Trees

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0094 - Binary Tree Inorder Traversal
0226 - Invert Binary Tree
0104 - Maximum Depth of Binary Tree
0543 - Diameter of Binary Tree
0110 - Balanced Binary Tree
0100 - Same Tree
0572 - Subtree of Another Tree
0108 - Convert Sorted Array to Binary Search Tree
0617 - Merge Two Binary Trees
0112 - Path Sum
0606 - Construct String From Binary Tree
0235 - Lowest Common Ancestor of a Binary Search Tree
0102 - Binary Tree Level Order Traversal
0199 - Binary Tree Right Side View
1448 - Count Good Nodes In Binary Tree
0098 - Validate Binary Search Tree
0230 - Kth Smallest Element In a Bst
0105 - Construct Binary Tree From Preorder And Inorder Traversal
0096 - Unique Binary Search Trees
0129 - Sum Root to Leaf Numbers
0337 - House Robber III
0951 - Flip Equivalent Binary Trees
1993 - Operations On Tree
0894 - All Possible Full Binary Trees
0513 - Find Bottom Left Tree Value
0669 - Trim a Binary Search Tree
0173 - Binary Search Tree Iterator
0538 - Convert Bst to Greater Tree
0124 - Binary Tree Maximum Path Sum
0297 - Serialize And Deserialize Binary Tree

Tries

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0208 - Implement Trie Prefix Tree
0211 - Design Add And Search Words Data Structure
0212 - Word Search II

Heap / Priority Queue

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0703 - Kth Largest Element In a Stream
1046 - Last Stone Weight
0973 - K Closest Points to Origin
0215 - Kth Largest Element In An Array
0621 - Task Scheduler
0355 - Design Twitter
1834 - Single Threaded Cpu
1845 - Seat Reservation Manager
1882 - Process Tasks Using Servers
1985 - Find The Kth Largest Integer In The Array
0767 - Reorganize String
1405 - Longest Happy String
1094 - Car Pooling
0295 - Find Median From Data Stream
1383 - Maximum Performance of a Team

Backtracking

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0078 - Subsets
0039 - Combination Sum
0077 - Combinations
0046 - Permutations
0090 - Subsets II
0040 - Combination Sum II
0047 - Permutations II
0079 - Word Search
0131 - Palindrome Partitioning
0093 - Restore Ip Addresses
0017 - Letter Combinations of a Phone Number
0473 - Matchsticks to Square
1849 - Splitting a String Into Descending Consecutive Values
1980 - Find Unique Binary String
1239 - Maximum Length of a Concatenated String With Unique Characters
0698 - Partition to K Equal Sum Subsets
0051 - N Queens
0052 - N Queens II

Graphs

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0463 - Island Perimeter
0953 - Verifying An Alien Dictionary
0200 - Number of Islands
0133 - Clone Graph
0695 - Max Area of Island
1905 - Count Sub Islands
0417 - Pacific Atlantic Water Flow
0130 - Surrounded Regions
1466 - Reorder Routes to Make All Paths Lead to The City Zero
0994 - Rotting Oranges
0286 - Walls And Gates
0909 - Snakes And Ladders
0752 - Open The Lock
0802 - Find Eventual Safe States
0207 - Course Schedule
0210 - Course Schedule II
1958 - Check if Move Is Legal
0934 - Shortest Bridge
0684 - Redundant Connection
0323 - Number of Connected Components In An Undirected Graph
0261 - Graph Valid Tree
1553 - Minimum Number of Days to Eat N Oranges
0127 - Word Ladder

Advanced Graphs

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0332 - Reconstruct Itinerary
1584 - Min Cost to Connect All Points
0743 - Network Delay Time
0778 - Swim In Rising Water
0269 - Alien Dictionary
0787 - Cheapest Flights Within K Stops

1-D Dynamic Programming

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0070 - Climbing Stairs
0746 - Min Cost Climbing Stairs
0198 - House Robber
0213 - House Robber II
0005 - Longest Palindromic Substring
0647 - Palindromic Substrings
0091 - Decode Ways
0322 - Coin Change
0152 - Maximum Product Subarray
0139 - Word Break
0300 - Longest Increasing Subsequence
0416 - Partition Equal Subset Sum
0120 - Triangle
0740 - Delete And Earn
0256 - Paint House
0377 - Combination Sum IV
0279 - Perfect Squares
1856 - Maximum Subarray Min Product
0983 - Minimum Cost For Tickets
0343 - Integer Break
0673 - Number of Longest Increasing Subsequence
0691 - Stickers to Spell Word

2-D Dynamic Programming

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0062 - Unique Paths
1143 - Longest Common Subsequence
0309 - Best Time to Buy And Sell Stock With Cooldown
0518 - Coin Change II
0494 - Target Sum
0097 - Interleaving String
0877 - Stone Game
0064 - Minimum Path Sum
0329 - Longest Increasing Path In a Matrix
0221 - Maximal Square
5782 - Maximum Alternating Subsequence Sum
0115 - Distinct Subsequences
0072 - Edit Distance
1220 - Count Vowels Permutation
0312 - Burst Balloons
1866 - Number of Ways to Rearrange Sticks With K Sticks Visible
0010 - Regular Expression Matching

Greedy

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0053 - Maximum Subarray
0055 - Jump Game
0045 - Jump Game II
1871 - Jump Game VII
0134 - Gas Station
0846 - Hand of Straights
1423 - Maximum Points You Can Obtain From Cards
1899 - Merge Triplets to Form Target Triplet
0763 - Partition Labels
0678 - Valid Parenthesis String
1921 - Eliminate Maximum Number of Monsters
1029 - Two City Scheduling

Intervals

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0057 - Insert Interval
0056 - Merge Intervals
0435 - Non Overlapping Intervals
0252 - Meeting Rooms
0253 - Meeting Rooms II
1288 - Remove Covered Intervals
1851 - Minimum Interval to Include Each Query

Math & Geometry

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0048 - Rotate Image
0054 - Spiral Matrix
0073 - Set Matrix Zeroes
0202 - Happy Number
0066 - Plus One
0009 - Palindrome Number
0263 - Ugly Number
1260 - Shift 2D Grid
0013 - Roman to Integer
0012 - Integer to Roman
0050 - Pow(x, n)
0043 - Multiply Strings
2013 - Detect Squares
1041 - Robot Bounded In Circle
0006 - Zigzag Conversion
2028 - Find Missing Observations

Bit Manipulation

Problem C C++ C# Dart GO Java JS Kotlin Python Ruby Rust Scala Swift TS
0136 - Single Number
0191 - Number of 1 Bits
0338 - Counting Bits
0190 - Reverse Bits
0268 - Missing Number
0371 - Sum of Two Integers
0007 - Reverse Integer
0067 - Add Binary

Need to update the README? Update the template instead.