GithubHelp home page GithubHelp logo

neetcode-gh / leetcode Goto Github PK

View Code? Open in Web Editor NEW
5.1K 5.1K 2.2K 7.59 MB

Leetcode solutions

License: MIT License

Python 7.33% Java 13.95% JavaScript 15.77% C++ 12.01% Swift 3.71% TypeScript 4.79% Ruby 1.46% C# 6.30% Rust 5.17% Kotlin 15.51% Go 4.38% Scala 0.87% C 8.42% Dart 0.33%

leetcode's People

Contributors

a93a avatar aadil42 avatar aakhtar3 avatar agnihotriketan avatar ahmad-a0 avatar akifhanilgaz avatar ap-repositories avatar caba5 avatar chriskheng avatar felivalencia3 avatar imaginate avatar julienchemillier avatar loczek avatar mahim1997 avatar maratkhakim avatar mdmzfzl avatar mhamiid avatar miladra avatar mitchellirvin avatar neetcode-gh avatar notauserx avatar saip7795 avatar sharmatushar1 avatar sujal-goswami avatar tahsintunan avatar tedtran2019 avatar udaygarg avatar unresolvedcold avatar veerbia avatar ykhan799 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

leetcode's Issues

Add time complexity to all solutions

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.

Counter to show total problems solved

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.

Lowest Common Ancestor of a BST

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) 

Defect JS Solution: 102. Binary Tree Level Order Traversal

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

Error
TestInput

Feature request: thumb-up/star

Can we get this feature so we can star the problems we think we need come back later to, or just are very interesting ๐Ÿค”

#286 Walls and Gates is missing initial for-loop

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))

Feature Request: Button to shuffle categories

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:

  1. Learning with easy questions
    I think we shouldn't use this feature in this round.
  2. Practicing with medium then hard questions:
    In this round, randomness (emphasis, only categories, not the content inside each category) could be very helpful to many people like me, especially when combine with #336.

Suggestion: Neetcode 75 seperate tab

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.

Option to show/hide the category names

It would be nice to have a button to hide category names like below. This is even more helpful when combine with #339.

image

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;
}

Code solutions differ from video.

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
}

74-Search-A-2D-Matrix.java is not a Binary Search

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.

Add an option to export and import progress

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.

Adding multiple solutions

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.

Other solutions

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.

C# Solutions

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.

Enhancement: Notes section for each question

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!

[chore] folder/file naming conventions

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?

36 Valid Sudoku fail for some invalid Sudoku

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"],
    ]
)

What type of license this repo has? Could you publish the LICENSE file to let know others how people can use the sources?

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!

Incorrect pattern for #121 (Best Time to Buy and Sell Stock)

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 :(

Not Included Problems.

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.

[FEATURE REQUEST] Pull Leetcode Status

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.

Add leading zeros to file name to keep them in order

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.