Unique Paths II - Leetcode 63 - Python

Поделиться
HTML-код
  • Опубликовано: 10 окт 2024

Комментарии • 16

  • @licokr
    @licokr 6 месяцев назад +3

    Great. You explain everything beginners might think and wonder. I can't complain anything about your videos. Thanks a lot neetcode

  • @superc91codm38
    @superc91codm38 Год назад +8

    There’s an O(1) solution using combinatorics in which we break it into two matrix and exclude all paths which strikes rock

    • @two697
      @two697 Год назад

      Could you elaborate on this? I'm not sure how this would be possible when there can be more than one obstacle

  • @Lucas-hr1mj
    @Lucas-hr1mj Год назад +4

    I like this problem. It is a very good and didactic example of dynamic programming.

  • @ronilitman7282
    @ronilitman7282 2 месяца назад

    Thanks for yet another great video! Small note: If I am not mistaken your recursive solution doesn't work because you never collect the count when you are arriving to your base case, e.g something like this - if r == M - 1 and c == N - 1:
    return 1

  • @גלריש
    @גלריש 3 месяца назад

    The explanation for this solution is amazing!

  • @KshitijKale
    @KshitijKale Год назад +4

    We could also do it in O(1) space by using our obstacleGrid array as the dp array. We will use the same logic but we will store the total paths by it's negative value to differentiate between number of paths and the obstacle. In the end we will return absolute of the negative value at 0, 0.

    • @nikhil199029
      @nikhil199029 Год назад +6

      Generally changing input is illegal

  • @hwang1607
    @hwang1607 Месяц назад

    here is a solution for unique paths 1 that I used this same logic to make:
    class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
    row = [0] * n
    row[n-1] =1
    for i in reversed(range(m)):
    for j in reversed(range(n-1)):
    row[j] = row[j] + row[j+1]
    return row[0]

  • @shashankgupta5687
    @shashankgupta5687 9 месяцев назад +1

    these dp problems takes days to understand and after watching editorials 5-6 times. Any suggestions pls??

  • @rafaeldietrich8050
    @rafaeldietrich8050 Год назад

    Great explanation as always!!

  • @krateskim4169
    @krateskim4169 Год назад

    Elegant explanation

  • @PrecisionWrittens
    @PrecisionWrittens 6 месяцев назад

    To help those a little confused by the final code, neet makes a slight space-optimization of only using a single array, which confused me a bit and I don't think would be reasonable for an interview. The unique-Paths-1 solution uses the much more straight-forward optimization of only using two-arrays (one to represent the prev row and the other to represent the current row) and I think you're better off just using that approach for this one. Recognizing that you don't actually need that 2nd array to populate the current rows dp values is not realistic for an interview imo. Clever AF though

  • @shavvasatya7131
    @shavvasatya7131 Год назад

    Great,as usual.

  • @nikhilsshastry6265
    @nikhilsshastry6265 11 месяцев назад

    This is a fake account, support the real neetcode

    • @NeetCodeIO
      @NeetCodeIO  11 месяцев назад +12

      Actually this is my second channel - i post all the new LC videos here now :)