LOWEST COMMON ANCESTOR OF A BINARY TREE II | PYTHON | LEETCODE 1644

Поделиться
HTML-код
  • Опубликовано: 24 фев 2022
  • In this video we are solving Lowest Common Ancestor of a Binary Tree II. This is an interesting problem because it's basically a carbon copy of the first iteration of this problem except this time we are not guaranteed to have the nodes P and Q exist in the tree.

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

  • @chasing_the_horizon
    @chasing_the_horizon Год назад +2

    Wow, the explanation was super clear! Thx, mate!

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

      Thanks! Make sure to subscribe if you haven’t already 😉

  • @symbol767
    @symbol767 2 года назад

    Within in the first 3 minutes of your video I figured out why my code wasn't working. Once I did a check for P and for Q separately first to confirm they both exist, my solution started working.
    All I had to do is check if P or Q doesn't exist and return Null, if they both exist, then I can do the normal "find ancestor" code.
    But of course this wasn't efficient enough, so thank you for showing me the optimized version

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

    Thank you . Your channel videos are super easy to understand.

  • @jaisoni1
    @jaisoni1 2 года назад

    Great Explanation! Thanks!

    • @crackfaang
      @crackfaang  2 года назад

      Glad you enjoyed the video! Make sure to subscribe so you don’t miss future videos

  • @jimmyahmed5424
    @jimmyahmed5424 2 года назад

    Thank you for explaining, it was helpful!

    • @crackfaang
      @crackfaang  2 года назад

      Glad you found the video helpful! Make sure to subscribe so you don’t miss other videos coming soon

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

    Wouldn't storing l and r result in an O(N) space complexity? Since the None value also takes space in memory as well.

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

    8:59 sorry I am confused here. If returning 4 or 5 doesn't matter, how would the algorithm make sure to return the correct answer, 5 but not 4?