Cache With Time Limit - Leetcode 2622 - JavaScript 30-Day Challenge

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

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

  • @NeetCodeIO
    @NeetCodeIO  Год назад +1

    Would've uploaded this earlier but someone broke youtube last night (was NOT me 😉)
    twitter.com/TeamRUclips/status/1659060023736016896

  • @saivenkatpokala8137
    @saivenkatpokala8137 Год назад +3

    Really appreciate the explanation of the js problem series

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

    The variety of stuff you can do here makes me wanna like Javascript

  • @Amar11115
    @Amar11115 Год назад +1

    Watched twice to fully understand. Thanks!

  • @rlizzy1
    @rlizzy1 Год назад +1

    Thx. i like the class sol much butter than the original one😃

  • @nChauhan91
    @nChauhan91 Год назад +1

    This pattern is very useful for something like an API cache

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

    I solved this one without using the set timeout callback, i just enter both the value and a expiration in an object as value. I do this live as well and have a periodic cleanup of expired cache items

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

    Was waiting for this

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

    wow, finally! thanks for this ^_^

  • @mohitsharma-ep9iy
    @mohitsharma-ep9iy 10 месяцев назад +2

    we can also do Object.keys(obj).length;
    if using object instead of map

    • @AbhinavMohanParaverse
      @AbhinavMohanParaverse 3 месяца назад

      Object.keys(obj): This method internally iterates over all the enumerable properties of the object to construct an array of keys. Therefore, its time complexity is O(n), where n is the number of enumerable properties in the object.
      .length: Accessing the length of an array is a constant-time operation, O(1).
      Due to the structure of accessing the length; it would require JavaScript to find all the keys first and THEN calculate the length; so this solution would result in iterating through all the keys, making it not efficient for this question.

    • @AbhinavMohanParaverse
      @AbhinavMohanParaverse 3 месяца назад

      *But, if you wanted, you could just make an extra "length" property in the class and update that property everytime a new key is added, and delete whenever the timeout function is executed
      This way, you could just access the length anytime (which would be in constant time)

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

    Thanks for your sharing~

  • @omeryasin622
    @omeryasin622 3 месяца назад

    I truly hate and love JS at the same time.

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

    I’ve only recently learned js (still learning) and I’m reluctant to use classes even though I came from a Java background. I almost always go with arrow functions but should I go with classes more?

  • @Android-17
    @Android-17 Год назад

    Thank you!
    Finally a easy one.

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

    Day 14 of doing the 30-day challenge with neetcode

  • @Eliv-d
    @Eliv-d Год назад +1

    hehehe finally :p

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

    You speak very fast. Is this your habit? My mother tongue is not English and it is difficult to understand you. Nevertheless I appreciate for videos.

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

    Спасибо, брат

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

    Hi, I have seen people bind 'this' in the constructor like this.get=this.get.bind('this'). But you don't do that and solution gets accepted either way. So can you explain what it does ?

  • @lucasluizss
    @lucasluizss 10 месяцев назад

    Great content! There is a change that would be nice in the get method: return this.cache.get(key)?.value ?? -1;