Day 2 | Advent of Code 2024 | Better Time Complexity

แชร์
ฝัง
  • เผยแพร่เมื่อ 4 ม.ค. 2025

ความคิดเห็น • 15

  • @dkd0m23
    @dkd0m23 หลายเดือนก่อน +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 หลายเดือนก่อน +4

    I'm so happy you're back

  • @f-8ght
    @f-8ght หลายเดือนก่อน +17

    Yo bro you are back

  • @daltonyon
    @daltonyon 15 วันที่ผ่านมา

    Great solutions!!

  • @gupta_samarth
    @gupta_samarth หลายเดือนก่อน +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 หลายเดือนก่อน +1

    HE IS BACK

  • @NKCSS
    @NKCSS หลายเดือนก่อน +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 😊

  • @uzdik.student
    @uzdik.student หลายเดือนก่อน +2

    legendary grandmaster

  • @bladekiller2766
    @bladekiller2766 หลายเดือนก่อน +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 หลายเดือนก่อน

      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 หลายเดือนก่อน

      @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.

  • @um12322
    @um12322 หลายเดือนก่อน

    hey u are back...

  • @abikarthick601
    @abikarthick601 หลายเดือนก่อน

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

    • @Errichto
      @Errichto  หลายเดือนก่อน +2

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

  • @muitd
    @muitd หลายเดือนก่อน +1

    whooa