Daily LeetCode Challenge (Day 50): Walking Robot Simulation

Поділитися
Вставка
  • Опубліковано 21 вер 2024
  • Welcome to Day 50 of my Daily LeetCode Challenge until I reach 1 year's worth of green contributions on GitHub! Today, we're solving Problem 874 - Walking Robot Simulation.
    🔗 Problem Link: leetcode.com/p...
    🚀 Check out my GitHub for all solutions: github.com/Jac...
    📅 Join me daily for a new LeetCode problem!
    Don't forget to like, comment, and subscribe if you like joining along to these types of videos!
    #LeetCode #CodingChallenge #DailyCoding #Programming #GitHub #Python

КОМЕНТАРІ • 14

  • @theragaru
    @theragaru 18 днів тому +1

    nice job! a couple comments from watching:
    1. 30:57 - Having the correct dx, dy for the directions makes a difference because the obstacles are given to us as (x, y). It wouldn't matter if there weren't obstacles because, you're right, it's an inf plane, but we need to make sure we align with the given obstacles.
    2. consider using an array dirs = [[0, 1], [1, 0], [0, -1], [-1, 0]] and curr_dir = 0. This way "turn right" becomes (curr_dir + 1) % 4 and "turn left" becomes (curr_dir + 3) % 4. Saves having to do the turnRight/turnLeft methods and prevents any possible bugs from introducing strings "north", "south", etc. This pattern is pretty reusable across 2D simulation problems
    3. 38:06 - You actually can do the maxDist calculation out of the for loop, no need to do it every step. It wasn't working for you because you were trying to use new_pos for the calculation when you can't rely on new_pos being a valid state (you break the loop when new_pos is an obstacle). (x, y) represents the last valid state and it can be used after the for loop. Essentially, if at some point during your walk of k steps you start to walk further away from the origin, the furthest you'll be is after your last step.

    • @alejandroill
      @alejandroill  18 днів тому +1

      WOAAAAAAAAAH, thank you so much for this feedback, this is AMAZING!! 🤩 I was definitely wondering about the bugs from (1) and (3), I didn't want to spend too much time thinking about it during the video since I had board-game night with my friends (I swear they always play my favorites while I'm recording... 🫠).
      For point (1) it definitely makes sense why that matters, in having to align with the obstacle positions. For point 3, that's such a bummer I didn't take 5 more seconds to investigate the issue 😭 I suppose if I changed checking new_pos to just (x, y) it would have worked, since (x, y) is now the current furthest position I can reach from taking the up-to k steps forward... 🫠 I gaslighted myself into believing that it's likely some edge case where the furthest position can be somewhere in the middle of the k-steps, which of course doesn't make sense now that I think about it after-the-fact 😔 I highly highly appreciate you for letting me know, that definitely clarifies it for me BIG time, and I'm actually gonna pin this comment cause this is amazing!!
      For point (2) that's actually a neat little trick 😯 I've never used an enum in python before, although I'm sure there's at least a library for it, so I always come up with something janky and hard-code the directions in these kinds of cases (since there's very few of them). But I completely didn't think of making them 0-3, and just adding by one + modulo-ing by 4 each time! And turn left I suppose you're adding by 3 since turning right three times essentially simulates the same result as turning left once -- that's actually so genius 🤯 Man I've got to say I REALLY, REALLY appreciate your comment, this is so insightful!!!
      This comment 10000% deserves to be pinned, I can't thank you enough for taking the time to write these details here to help me and potentially everyone watching!! You're the man @theragaru 😎💪
      If you don't mind me asking, I'd love to get to learn more about you, what inspires you to do Leetcode, how long you've been doing it, and what your goals are!! Are you maybe a competitive programmer, a student, or someone trying to land a job? I would love to know!!
      Thank you so much once again for your insightful comment, it's always super helpful to have someone check & review your work, especially in Leetcode! If you find these kinds of details to comment on in my future videos as well, please feel free to point them out as it really helps me learn, and I’m sure others as well!! Thanks again @theragaru, and here’s a big cheers to you 🍻

    • @theragaru
      @theragaru 17 днів тому +1

      @@alejandroill game night should always take precedence! you definitely would've realized the bug if you took the time
      I'm a faang type engineer grinding leetcode for interviews. I think your channel got recommended to me because I've been watching channels like NeetCode😆 it's been cool to watch someone else do the problem from scratch to see what intuitions/steps I may have missed, as opposed to watching someone just review the problem already knowing the answer. thanks for uploading!

    • @alejandroill
      @alejandroill  17 днів тому +1

      Haha hopefully and omg no way, that's so cool!! I work at Microsoft myself as a SWE, although I know that's technically not FAANG 😔 (or is it MANGA now? 🤔).
      And yeah that was definitely the goal!! I noticed that almost every other Leetcode channel would present the raw solutions themselves, instead of showing the struggling & thought-process that would arrive towards the optimal solution. One thing I realized VEEEEEERY quickly during University is that understanding the solution to a problem is MUUUUUUCH easier than trying to come up with the optimal solution yourself 😅 So I figured by making these types of videos they could either be used to code alongside to, or to see step-by-step how one may go from Idea 1 to Idea 2, ..., to Idea N until reaching a finally working solution 😊
      And of course!! If you ever have any feedback or want to keep having a conversation going together, please always feel more than welcome to do so!! I sincerely appreciate your comments and informative feedback @theragaru🥰

  • @saag420
    @saag420 18 днів тому +1

    100 DAYS BADGE, LET'S GOOOO!!!!!!! 🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥🔥
    I'M SOOOOO HAPPYYY FOR YOUUUUUU 🎉🎉🎉🎉

    • @alejandroill
      @alejandroill  18 днів тому +1

      YESSSSSSSSSSS I’m so happy about that 🥰 FIRST BADGE ON THE CHANNEL!!! 🤯🤯🤯

  • @praful_creations_0
    @praful_creations_0 18 днів тому +1

    First 🥇🥇

  • @praful_creations_0
    @praful_creations_0 18 днів тому +1

    Can you do this in c++

    • @alejandroill
      @alejandroill  18 днів тому +1

      Oof, I could certainly give it my best shot, though I’ve never coded in C++ before. I suppose it can’t be too much different from C…
      I like Python (even though it’s MUCH slower) since it allows you to focus less on implementation details and more on solving the actual problem. Even something like converting a uint to a string or vice-versa might be trivial in Python but a nightmare in C++ 🫠 It depends on your goals however, I know most competitive programmers tend to resort to C# for solving these problems to make their solutions as fast as possible 😁
      One thing that’s nice about Leetcode is that even though Python is much slower, your submissions get ranked against other Python solutions, so you can already reasonably-gauge how efficient your solution compared to others. Let me know what motivates you to solve Leetcode and what your goals are, and maybe I can try writing some of these solutions in C++ as well - although fair warning that I’ve never coded in the language before 😅

    • @praful_creations_0
      @praful_creations_0 18 днів тому +1

      @@alejandroill No worries 😄, You are great In Python 👍
      I was just asking , cause i was not getting it's solution 😅 that time.
      but u did it very well and
      Congratulations for your BADGE 👏

    • @alejandroill
      @alejandroill  18 днів тому +1

      Ayyyy thank you so much @praful_creations_0!!! 🤩 And ahhhh I see, and yeah it might be tricky in C++ since I’m not sure if it’s similar to Java & C# where you have a bunch of libraries you can resort to for common DS like hash-sets (since I don’t know of any in C).
      If it helps and you’re new to Python, or at least would benefit from a brief review of the most useful parts of the language for solving Leetcode problems, I’d highly recommend the video titled “Python for Coding Interviews - Everything you need to Know” by Neetcode. It’s the video I watched before I started solving Leetcode problems, and it’s SUUUUUUUUUUPER useful. That’s where I learned about tools like collections.deque() and heapq that I didn’t know about before, and it really is legitimately “everything you need to know about Python” for coding interviews 😁
      Let me know if you find it useful, and thanks again for your super kind comment, these really help keep me going 🥰 I hope to keep hearing from you my friend, and let me know where you’re at in your own Leetcode journey!!! 🤩🥇

    • @praful_creations_0
      @praful_creations_0 18 днів тому +1

      @@alejandroill bro i Really appreciate you , Like you are replying in such a big paragraph, that takes lot of effort.
      I wish you will achieve a great success on your UA-cam journey ⚡😌

    • @alejandroill
      @alejandroill  18 днів тому +2

      @praful_creations_0 The pleasure is all mine! From my view you guys kindly take the time out of your day to leave a comment on my channel, so it’s only fair that I give my most well-thought-out response every single time 🥰
      I really appreciate your kind words, and I can’t wait to see how this puppy takes off over time!! 🚀 If you ever have any suggestions or types of videos that you’d find useful or would like to see, please let me know ☺️ Rock on my friend, and best of luck with your Leetcode journey too!!🤘🏻