Integer to English Words - Leetcode 273 - Python

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024

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

  • @davidorbang7152
    @davidorbang7152 หลายเดือนก่อน +29

    For anyone implementing this here are the 2 hashmaps:
    ones_map = {
    1: "One",
    2: "Two",
    3: "Three",
    4: "Four",
    5: "Five",
    6: "Six",
    7: "Seven",
    8: "Eight",
    9: "Nine",
    10: "Ten",
    11: "Eleven",
    12: "Twelve",
    13: "Thirteen",
    14: "Fourteen",
    15: "Fifteen",
    16: "Sixteen",
    17: "Seventeen",
    18: "Eighteen",
    19: "Nineteen",
    }
    tens_map = {
    20: "Twenty",
    30: "Thirty",
    40: "Forty",
    50: "Fifty",
    60: "Sixty",
    70: "Seventy",
    80: "Eighty",
    90: "Ninety"
    }

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

      my hero

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

      Our lord saviour is here

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

      🐐

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

      class Solution:
      def numberToWords(self, n: int) -> str:
      if not n: return 'Zero'
      o,h,sfx,d=[],'Hundred',['','Thousand','Million','Billion'],{1:'One',2:'Two',3:'Three',4:'Four',5:'Five',6:'Six',7:'Seven',8:'Eight',9:'Nine',10:'Ten',11:'Eleven',12:'Twelve',13:'Thirteen',
      14:'Fourteen',15:'Fifteen', 16:'Sixteen',17:'Seventeen',18:'Eighteen',19:'Nineteen', 20:'Twenty', 30:'Thirty', 40:'Forty',50:'Fifty', 60:'Sixty',70:'Seventy',80:'Eighty', 90:'Ninety'}
      def mk(n,p):
      if n:
      a,n=divmod(n,1000)
      mk(a,p+1)
      if n:
      a,n=divmod(n,100)
      if a:o.append(d[a]);o.append(h)
      if n>19:
      a,n=divmod(n,10)
      o.append(d[a*10])
      if n:o.append(d[n])
      if p:o.append(sfx[p])
      mk(n,0)
      return ' '.join(o)

  • @sundew_ii
    @sundew_ii หลายเดือนก่อน +56

    u know its gonna be a pain when the solution video is 20+ mins long

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

      Before opening lc daily i get notification of neetcode video and from the length of the video i understand the level of today's question. 😂

    • @user-dx6to8xe2v
      @user-dx6to8xe2v หลายเดือนก่อน

      @@shubham6523 🤣🤣

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

      going through all the dynamic programming videos, they're all 20-30 mins long

  • @invalidfusion9806
    @invalidfusion9806 หลายเดือนก่อน +31

    Problem's name : 😇
    Problem's solution:😈

  • @NeetCodeIO
    @NeetCodeIO  หลายเดือนก่อน +56

    can someone remind me, what's the meaning of life?

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

      Maybe solving a hard problem on first try 😢

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

      To Enjoy and have fun 🎉

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

      42

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

      For devs it’s to suffer.

    • @LuciferMorningstar-ru7wd
      @LuciferMorningstar-ru7wd หลายเดือนก่อน

      Solve Edge Cases 😅 thanks for the solution

  • @user-tt3lb1yy6i
    @user-tt3lb1yy6i หลายเดือนก่อน +30

    The problem with a million edge cases

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

    I'm surprised the problem is so much disliked. I liked it. It's clear and practical, in contrast to all those "count the number of solutions and because nobody cares return it by modulo" .

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

    I encountered this problem in one of my interviews.
    The thing about this question is
    It is one of the hardest questions yet one of the most useful.
    You can literally judge an applicant with this kind of question.

  • @user-wj1zq6je8y
    @user-wj1zq6je8y หลายเดือนก่อน +6

    it took me 3 hours to do it with recursion , the meaning of life is to suffer

  • @DashingJack
    @DashingJack หลายเดือนก่อน +5

    1:47 I think I know how he got to know that it could be zero.😂

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

    Dude solved it in 38 mins😧💀☠

  • @Notezl
    @Notezl หลายเดือนก่อน +3

    3rd time requesting- please please solve this- '815 bus routes' on leetcode.

  • @Harshsahu.0
    @Harshsahu.0 25 วันที่ผ่านมา +1

    switch(num) {
    case 1: return "One";
    case 2: return "Two";
    case 3: return "Three";
    .....
    .....

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

    Opening line had me thinking... hmm theres gotta be something useful in this problem... and then you cracked me up

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

    Yep, solved it in about an hour. It took 4 submission attempts and then I posted 2 successful submissions, so it lowers success rate quite a lot
    From now on I'll first setup sandbox locally, debug everything, search discussion section for test cases and only then submit the code

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

    Nice to see your initial thought process & previous codes

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

    we should use if condition inside the get_string() to check if the tens in null or not. It will not change the output but will improve code clarity and maintainability.

  • @user-dp9gi1vg8r
    @user-dp9gi1vg8r หลายเดือนก่อน

    Really love to start my day with 'pain in the ass' daily problem, thank you, NeetCode!

  • @maryannegichohi7063
    @maryannegichohi7063 24 วันที่ผ่านมา

    Very nice explanation and it was very helpful

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

    Easy but tedious problem.

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

    There's a chrome extension called Leetcode Fix that shows the dislikes. If you're into that kind of thing

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

    did it in 2 and a half hours, went the if else bell route

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

    imagine having this problem but for french digit representation

  • @rahulsihara8946
    @rahulsihara8946 หลายเดือนก่อน +3

    if i see this , i am walking out of the interview room.
    Jokes aside, thanks for the explanations.

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

    im gonna cry

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

    Using arrays instead of hash maps is way less tedious to code up.

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

    The meanint of life is to tolerate what life opposes on us RT

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

    got this on an Amazon Phone Screen had less than 30 mins to solve with the additional requirement to add the "and" in the corresponding spots... I failed lol

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

    00:08 🤣😅😆

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

    Am I the only one who enjoyed this? Not exactly hard, but a bunch of little parts to figure out and put together.

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

    If it took you 38 minutes, for common plebs like me will be impossible in an interview setting...

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

    Imagine this being the first hard problem you solve🙂
    And yes i m this unlucky soul.....

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

    res.insert(0,s+postfix[i])
    can use this instead of reverse

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

      Yes but it's slower

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

      @@michaelroditis1952 giving better runtime than append-reverse one
      Though can't compare based on leetcode runtime
      As inserting at pos 0 everytime isn't it 0(1) like append?

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

      @@sankhadip_roy Inserting at position 0 is the worst because it must move n elements. Better to use deque

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

      @@michaelroditis1952 understood

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

      @@michaelroditis1952 Understood

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

    opening line im dying lol

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

    Anyone - What do you want to be when you grow up?
    Me - Not a Programmer 😪

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

    class Solution:
    def numberToWords(self, n: int) -> str:
    if not n: return 'Zero'
    o,h,sfx,d=[],'Hundred',['','Thousand','Million','Billion'],{1:'One',2:'Two',3:'Three',4:'Four',5:'Five',6:'Six',7:'Seven',8:'Eight',9:'Nine',10:'Ten',11:'Eleven',12:'Twelve',13:'Thirteen',
    14:'Fourteen',15:'Fifteen', 16:'Sixteen',17:'Seventeen',18:'Eighteen',19:'Nineteen', 20:'Twenty', 30:'Thirty', 40:'Forty',50:'Fifty', 60:'Sixty',70:'Seventy',80:'Eighty', 90:'Ninety'}
    def mk(n,p):
    if n:
    a,n=divmod(n,1000)
    mk(a,p+1)
    if n:
    a,n=divmod(n,100)
    if a:o.append(d[a]);o.append(h)
    if n>19:
    a,n=divmod(n,10)
    o.append(d[a*10])
    if n:o.append(d[n])
    if p:o.append(sfx[p])
    mk(n,0)
    return ' '.join(o)

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

    For the real DSA heads who do this shit for fun 😢😂

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

    tedious indeed

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

    thank you for reminding me to put dislike after solving this problem 👍

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

    Only stupid people from HR will ask this problem in Interview.

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

    spain

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

    i wish u can hear me clappingg !

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

    How is this a hard problem? There is not even a proper algorithm here. literally a bruteforce solution is the correct one!

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

    Nah tbh i enjoyed this problem

  • @VinayKumar-xs6el
    @VinayKumar-xs6el หลายเดือนก่อน

    i too wanted to dislike just bcoz of i am not good at spellings i dont 11-19 and some more

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

    you care about me?

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

      i care

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

    I solved it with arrays instead and using indexes divided and moded by 1000:
    below_20 = [
    '', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten',
    'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen', 'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen'
    ]
    tens = [
    '', '', 'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty', 'Ninety'
    ]
    thousands = ['', 'Thousand', 'Million', 'Billion']
    def num_to_string(n):
    if n == 0:
    return ''
    ans = ""
    if n >= 100:
    ans += below_20[n//100] + " Hundred "
    n = n%100
    if n < 20:
    return ans + below_20[n]
    if n < 100:
    return ans + tens[n//10] + " " + below_20[n%10]
    res = ""
    for i, s in enumerate(thousands):
    digit = num % 1000
    nn = num_to_string(digit).strip()
    res = nn + (( " " + s ) if nn else "") + (" " + res.strip() if res else "")
    num = num // 1000
    return res.strip()