DAY 76 of Leetcode Daily - CHALLENGER

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • Welcome to Day 76 of my Daily LeetCode Challenge until I reach 1 year's worth of green contributions on GitHub! Today, we're solving Problem 1381 - Design a Stack With Increment Operation.
    🔗 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
    P.S. As Noor mentioned (pinned comment), there’s a more efficient way to do this problem. One can leverage the fact that increment function requires elements from [0,k) be incremented, with 0 always being fixed (bottom of stack), to construct an overall O(1) algorithm instead of O(k) for increment solution. My new solution can be found over at: github.com/Jac....

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

  • @noornasri5753
    @noornasri5753 3 дня назад +2

    This is a leetcode easy because of the constraints, should force you to do O(1) for the calls. You just need to keep track of the the sizes to increment when popping.

    • @alejandroill
      @alejandroill  3 дня назад +2

      Bruh there's no wayyyy, I literally double-checked that there was no follow-up questions or additional constrains... even the hints suggested to write the increment function in O(k) time... 🫠 That idea is very clever though, reminds me of lazy loading with things like IEnumerable in C#. Keep up the good work Noor!! 🙌

    • @noornasri5753
      @noornasri5753 3 дня назад +1

      @@alejandroill you should redo it smh, what was that about not taking the easy way?

    • @alejandroill
      @alejandroill  3 дня назад +1

      ​@noornasri5753 Haha okok you're right sir :p In the video I thought of a small optimization idea but quickly got turned away realizing that I'd have to keep track of intervals, but since we're always doing the k bottom elements, the interval is always [0, k]. I.e. the left index is always fixed (since it's always bottom k), so like you said we can keep track of these sizes to apply them again as an offset when popping. I'll rewrite my solution and send a link to it here once I'm finished writing it :)
      EDIT: In case you cannot see my message with the new solution link below, I’ve also posted it to the bottom of the description just in case :)

    • @alejandroill
      @alejandroill  3 дня назад +2

      Here's the link to my new solution: github.com/Jackbar21/Leetcode/blob/main/1497-design-a-stack-with-increment-operation/design-a-stack-with-increment-operation.py
      It now beats 99.18%!!! 🤯 Thank you so much for your comment Noor, I'm happy I was able to notice that slight optimization thanks to you!! 😁🤩

    • @noornasri5753
      @noornasri5753 3 дня назад +1

      @@alejandroill 3 videos on 1 day? Kinda much man