Day 2 | Advent of Code 2024 | Better Time Complexity

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

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

  • @dkd0m23
    @dkd0m23 2 месяца назад +12

    I just took the simple approach of erasing one element and checking each time if the sequence is safe :)
    I knew there was a better way! Nice to see it here :)

  • @kevinkuruvilla6435
    @kevinkuruvilla6435 2 месяца назад +4

    I'm so happy you're back

  • @f-8ght
    @f-8ght 2 месяца назад +17

    Yo bro you are back

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

    Great solutions!!

  • @gupta_samarth
    @gupta_samarth 2 месяца назад +1

    A good way to refactor, if you didn't want repeated code would be, instead of returning a boolean from the isOK function, we could return first index which causes an issue, and SZ+1 or some sentinel if good.

  • @ghg6525
    @ghg6525 2 месяца назад +1

    HE IS BACK

  • @bladekiller2766
    @bladekiller2766 2 месяца назад +1

    For Part 2 I solved it just by checking whether exactly one is bad level:
    - Case when exactly one inc/dec is incorrect
    - Case when exactly one has incorrect distance (x < 1 or x > 3)
    Total 5 cases need to be checked for each report, which is O(N)

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

      if you have one bad level, couldn't that mean that you have two wrong distances? one leading to it and one leading away from it?

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

      @difflocktwo correct, that's why I mentioned 5 cases, 1 for the initial report and 2 for each of the cases that I mentioned.
      Be careful, I'm counting the direction case as one case because I'm considering only the direction which has the most correct levels.
      Also, when I have bad distance level Im just considering the next level for conparison, so effectively, I just store an array which tells whether from the current level away to the next there is valid distance, if not, then not safe.

  • @uzdik.student
    @uzdik.student 2 месяца назад +2

    legendary grandmaster

  • @NKCSS
    @NKCSS 2 месяца назад +1

    For part two, when you spot an issue, removing that index plus the next is enough, except where the index is 1, then you also need to try to remove index 0, as 0..1 is the setup for asc/desc which can be wrong. After reading all the Reddit posts, was happy that I figured that out while on stream, as most people didn’t seem to get that bit 😊

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

    hey u are back...

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

    Can't you have count of increasing and decreasing number and check whether atleast one of those is 0 or 1

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

      Erasing an element by change the number of increments by 0 or 1 or 2. So it's not that easy.

  • @muitd
    @muitd 2 месяца назад +1

    whooa

  • @HiPh0Plover1
    @HiPh0Plover1 26 дней назад

    your explanations are very slow my friend especially for us experts software engineers , can you please explain things faster ? :D