Memoize - Leetcode 2623 - JavaScript 30-Day Challenge

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

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

  • @julianelmasry9556
    @julianelmasry9556 ปีที่แล้ว +6

    i used an array as the key here and it worked fine

    • @NeetCodeIO
      @NeetCodeIO  ปีที่แล้ว +24

      Good catch. The reason that works in this case is our function is only called with integers, so JavaScript implicitly converts the array into a string, e.g. '[1, 2, 3]' -> '1, 2, 3'.
      But if you try doing that with an array of objects, it will be implicitly converted to this: ''[object Object],[object Object],[object Object']'
      Obviously, in that case the key would not be unique. JSON.stringify() prevents this bug, because it gives us the most precise string representation of the array/objects.

    • @julianelmasry9556
      @julianelmasry9556 ปีที่แล้ว +2

      @@NeetCodeIO thanks for the clarification

    • @Android-17
      @Android-17 ปีที่แล้ว

      @@NeetCodeIO thanks!

    • @Aashiqui-pf7ni
      @Aashiqui-pf7ni 9 หลายเดือนก่อน

      bro please help to study hard and understand the js concept more ,where I can study the concept in js

  • @Eliv-d
    @Eliv-d ปีที่แล้ว +4

    Your videos are so helpful ! thank you from bottom of my heart!!

    • @NeetCodeIO
      @NeetCodeIO  ปีที่แล้ว +1

      Glad I could help =)

  • @pranavkumar9175
    @pranavkumar9175 ปีที่แล้ว

    very nicely explained, thankyou so much.

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

    great explanation, thank you

  • @Android-17
    @Android-17 ปีที่แล้ว

    I used *args.join("-")* as the key which worked for this problem with integers.
    But *JSON.stringify()* is a better option.
    THANKS!

  • @ar.ventures
    @ar.ventures ปีที่แล้ว +1

    nit:- The Leetcode problem number in the title says 2629 but in fact is 2623. Might make it difficult for people searching for a solution by the problem number. Also, thanks for the daily uploads. They make us all better programmers each day - one bit at a time :)

  • @shoaibhasan4026
    @shoaibhasan4026 ปีที่แล้ว

    thanks man for great explanation .

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

    thankyou so much it helps me alot

  • @TheMarkBrut
    @TheMarkBrut ปีที่แล้ว

    2:22 like! I do not now same about React, because u now

  • @chizuru1999
    @chizuru1999 ปีที่แล้ว +1

    I am an experienced JS developer (yes experienced for job tasks i mean 😂) but this is great for logic building. Thanks a lot 🫰 keep uploading.
    Also can you please share your website graph config? I want to take a look at it. It uses the antv x6 graph right?

  • @vixguy
    @vixguy ปีที่แล้ว +2

    Day 9 of doing the 30-day challenge with NeetCode

  • @teqarine5752
    @teqarine5752 ปีที่แล้ว +2

    in the stringify function, why do we use args, and not the spread operator ...args?

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

      because args act as a single element but ...args act as multiple elements

  • @朴云峰
    @朴云峰 ปีที่แล้ว +2

    let's say we memoized a function sum, should memoize(1,2,3) and memoize(3,2,1) be considered the same and the callCount be 1?

    • @navenkumarduraisamy6260
      @navenkumarduraisamy6260 ปีที่แล้ว +1

      Ideally not, it's not always the same fn that is passed as a parameter to memoize function

  • @Amar11115
    @Amar11115 ปีที่แล้ว

    2:24 a fun moment 😆

  • @krateskim4169
    @krateskim4169 ปีที่แล้ว

    Thank you so much

  • @inanismailov
    @inanismailov ปีที่แล้ว

    I see that on line 12 you have cache[key] = fn(...args);
    My question is, if cache is declared as a const, how are you able to add to it?

    • @inanismailov
      @inanismailov ปีที่แล้ว

      I have answered my own question, using const simply means you cannot reassign the variable name. You CAN still mutate it.

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

      I have learnt frm your answer to your question . Thak you 😂😂😂😂

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

      const as in non changeable only applies to primitives and not for non primitive objects like arrays

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

    Did you solve memorize 2 ?
    I didnt find it :(

  • @AyoubRABIYAE
    @AyoubRABIYAE ปีที่แล้ว

    Amazing

  • @navenkumarduraisamy6260
    @navenkumarduraisamy6260 ปีที่แล้ว

    Taking about the design pattern,
    Isn't this strategy design pattern?
    Because we could pass any parameter(strategy) to memoize.

  • @anishkarthik4309
    @anishkarthik4309 ปีที่แล้ว

    what is difference between
    a)
    const key = args.toString();
    and
    b)
    const key = JSON.stringify(args);
    ?
    why b) is faster than a) by 2-3 times always???

    • @StoneAge20908
      @StoneAge20908 ปีที่แล้ว

      We can re convert to JSON object using JSON.parse().

  • @hoyinli7462
    @hoyinli7462 ปีที่แล้ว

    2:25 if you are writing angular, why don't you go for typescript in daily js challenge? XD
    keep it up

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

    doesnt work ... . I get fn proto

  • @StoneAge20908
    @StoneAge20908 ปีที่แล้ว

    What if order of arguments is different but values are same

    • @aaa-os3pj
      @aaa-os3pj หลายเดือนก่อน

      Different key obviously can't use cached value