neetcode-gh / leetcode Goto Github PK
View Code? Open in Web Editor NEWLeetcode solutions
License: MIT License
Leetcode solutions
License: MIT License
In the walk through video's you go through the time and space complexity of any given problem.
I thought it would be nice if we added the time and space complexity on the site neetcode.io associated with each problem.
One approach could be to hard code it on the site.
Another rather simpler approach would be to have it in the github file with the code for each algorithm.
Can you please implement login system on Neetcode.io, further this could allow us to make our own problem list (customized) in the future.
Under the binary tree section, the question that is linked to for "Lowest Common Ancestor of a BST" is incorrect. It currently links to 236. Lowest Common Ancestor of a Binary Tree when it should link to 235. Lowest Common Ancestor of a Binary Search Tree
.
The BST version is also tagged "Easy" on leetcode, but "Medium" on neetcode
In addition to the number of problems solved per pattern/topic, I think it would be useful to have a total number of problems solved counter somewhere.
e.g. 34/150 on Neetcode 150; a sum of problems solved across all patterns.
The 8th challenge in Linked List says Find the Duplicate Number but its related topics are array, 2 pointers, binary search and bit manipulation instead. Maybe move this to another group?
As the title says the solution is not correct. There are two problems.
First it should check if the character is not alphanumeric in the while loops. The current solution checks if it is alphanumeric
Second the isAlphaNumeric method is implemented incorrectly.
Since the question specifies a Binary Search Tree, and that q
and p
are nodes in the tree, the solution can be further simplified to be a search for the node whose value is between p
and q
for instance
class Solution:
def lowestCommonAncestor(self, root: 'TreeNode', p: 'TreeNode', q: 'TreeNode') -> 'TreeNode':
if p.val <= root.val <= q.val or p.val >= root.val >= q.val:
return root
if p.val < root.val and q.val < root.val:
return self.lowestCommonAncestor(root.left, p, q)
else:
return self.lowestCommonAncestor(root.right, p, q)
The provided Javascript solution for LeetCode 102. Binary Tree Level Order Traversal has a defect when the input array is an empty array
The error being returned is:
Line 23 in solution.js
temp.push(subtree.val)
^
TypeError: Cannot read properties of null (reading 'val')
Line 23: Char 31 in solution.js (levelOrder)
Line 42: Char 19 in solution.js (Object.<anonymous>)
Line 16: Char 8 in runner.js (Object.runner)
Line 33: Char 26 in solution.js (Object.<anonymous>)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Can we get this feature so we can star the problems we think we need come back later to, or just are very interesting ๐ค
@neetcode-gh
I've created #250 Kotlin solutions over here please take a look
Can we have a feature to mark that a problem is "in progress" or "seen"? I don't like checking a problem when I had to look at the solution.
Missing logic after line 17, the queue q
is currently always empty.
Here is the missing logic after line 17:
for r in range(ROWS):
for c in range(COLS):
if rooms[r][c] == 0:
q.append([r, c])
visit.add((r, c))
Please shot a video for the problem https://leetcode.com/problems/two-sum-iv-input-is-a-bst/
It need not be stored in database or server. We can use Local storage to store the notes
It would be nice to be able to shuffle the categories. I mean only the categories, NOT the order of problems inside each category.
Normally, we could split our DSA interview study into 2 rounds:
Any chance we could get a Neetcode 75 seperate tab (next to Neetcode 150 and Blind 75).
I've completed the Blind 75 and have moved on to Neetcode 150 and would like to keep seperate track of the completion of the list. A seperate tab would filter out the Blind 75 questions.
It would be nice to have a button to hide category names like below. This is even more helpful when combine with #339.
Currently, I use developer tools with this css:
body {
counter-reset: category;
}
app-pattern-table app-accordion {
counter-increment: category;
}
app-pattern-table app-accordion button.accordion::before {
content: "Category " counter(category);
}
app-pattern-table app-accordion button.accordion > p:nth-child(1) {
display: none;
}
It seems some solutions differ from the video, for 268-Missing-Number
this code is shown in the video and appears as the python solution on neetcode.io:
class Solution:
def missingNumber(self, nums: List[int]) -> int:
res = len(nums)
for i in range(len(nums)):
res += (i - nums[i])
return res
However the Java, C++ and proposed Typescript solution (#422) use slightly different algorithms:
Java:
class Solution {
public int missingNumber(int[] nums) {
int sum = 0;
int total = nums.length * (nums.length+1)/2;
for(int i = 0; i < nums.length; i++){
sum += nums[i];
}
return total - sum;
}
}
C++:
class Solution {
public:
int missingNumber(vector<int>& nums) {
int n = nums.size();
int result = n;
for (int i = 0; i < n; i++) {
result ^= i ^ nums[i];
}
return result;
}
};
Typescript:
function missingNumber(nums: number[]): number {
let sum: number = 0
let total: number = (nums.length * (nums.length + 1)) / 2
for (let i = 0; i < nums.length; i++) {
sum += nums[i]
}
return total - sum
}
The Java solution is a linear search and NOT a binary search. Worst case runtime for the code is O(m+n) which occurs if the target value is at the bottom left corner of the matrix. Binary search solution should be O(logm) + O(logn) as described in the video solution.
Would find it highly convenient if we added the ability to close the Youtube popup modal on "esc" keypress
Currently, the progress on the site can be lost when the browser cache is cleared, browser is reinstalled, etc. I think it would be great if an export/import progress feature is added to the site, so that users can back up their progress. It would also be useful in cases like when a user wants to use the site in a different computer. They can export the progress in the old computer and import it in the new computer's browser to resume progress on the new machine.
Hey Neetcode, can i add different solutions to existing problems? If so, should i add the solution to the existing solution file?
For me personally, it really helps to look at different solutions to understand the problem completely.
Hello @neetcode-gh, I wanted to ask you whether I should contribute by pushing solutions to leetcode questions that are not solved on the youtube channel. Thank you.
In the future will it be possible to contribute C# solutions. I know the language is very similar to Java (although with many major differences) but as an engineer who is "all in" on Microsoft, .NET, and ASP it'd be nice to have C# solutions available. I'd be happy to contribute some as I learn.
According to this link, https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/ has been converted to a medium problem.
Adding a section for users to type notes (cached in the browser perhaps) would be very helpful. The notes section on the Blind 75 excel sheet that NeetCode created was super helpful. I would love the ability to write my own notes on how I solved the problems. Thanks!
we should pick a naming convention and update the entire repo to use that naming convention
currently for files we have a weird combination of Pascal-and-Spinal-Case
for the languages that have separated the neetcode 150 and the blind 75, we don't have a consistent convention for directory naming.
i'd propose moving to spinal-case
across the board, but don't feel strongly about it. curious if anyone has strong opinions.
when we do the refactor, we should do it in chunks (maybe folder by folder) to make the PR reviews easier.
@neetcode-gh any preferences?
https://github.com/neetcode-gh/leetcode/blob/main/36-Valid-Sudoku.py
Is there a valid for
Solution().isValidSudoku(
[
["9","2","3","4","5","6","7","8","."],
[".",".",".",".",".",".","6","5","2"],
[".",".",".",".",".",".",".","4","3"],
[".",".",".",".",".",".","9",".","4"],
[".",".",".",".",".",".",".",".","5"],
[".",".",".",".",".",".",".",".","6"],
[".",".",".",".",".",".",".",".","7"],
[".",".",".",".",".",".",".",".","8"],
[".",".",".",".",".",".",".",".","9"],
]
)
Hey guys, hi @neetcode-gh, awesome site! i find a lot of solutions very useful but can i share them with students on lectures or in youtube videos? The LICENSE file would be great to have to let know others how people can use the sources. Could you release one?
Github has great page dedicated to opensource licenses: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository
All the best!
Hi there!
I found the problem 121 (Best Time to Buy and Sell Stock) in "Sliding Window" section on neetcode.io
But in the video author is using "Two Pointers" pattern for his solution, not "Sliding Window".
So I believe this task should be moved to "Two Pointers" section.
I spent couple of hours trying to solve it with "Sliding Window" before I gave up, watched the video solution and found that we need another pattern here :(
I would like to suggest adding granularity in the site https://neetcode.io/ (Easy / Medium / Hard) to the problems for better visibility and tracking
Please shot a video for the problem https://leetcode.com/problems/increasing-order-search-tree/
Would be awesome to have a button that pick a random question (unsolved)
A C++ solution to the 98.Validate Binary Search Tree problem which follows Neetcode's explanation in the video.
It would be useful to add time and space complexities in the solutions. Thanks.
In https://neetcode.io/ the problem 141. Linked List Cycle is marked as Medium, but in LeetCode it has been updated to Easy.
Hey guys, I want to contribute to this amazing repo. But I have a question before I do that.
Can we put solutions to the questions that haven't been solved by the neetCode guy?
Sorry, I don't know your name so I said, neetCode guy.
In neetcode.io, the link for the 252. Meetings Rooms II goes to https://www.lintcode.com/problem/919/ instead of https://leetcode.com/problems/meeting-rooms-ii/
Hey can I contribute solutions with C++?
The Array & Hashing problem Encode and Decode Strings is currently behind the Leetcode premium paywall. Was it always like this? Any thoughts how this should be handled?
@neetcode-gh
I've created some ruby solutions, please take a look.
Instead of having users manually confirm whether they have completed a problem from neetcode, you can offer a button to directly pull the data from the user's leetcode profile.
A neat little python script can add leading zero's to all the file names this way they will appear in order.
Something like this:
import sys,os,re
for file in sys.argv[1:]:
if __file__ in file: continue
number, name = file.split('-', 1)
number = '{:0>4}'.format(number)
new_name = f'{number}-{name}'
os.rename(file,new_name)
PR #335 is the result of the above program.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.