Тёмный

Integer to Roman - Leetcode 12 - Python 

NeetCode
Подписаться 755 тыс.
Просмотров 65 тыс.
50% 1

🚀 neetcode.io/ - A better way to prepare for Coding Interviews
🐦 Twitter: / neetcode1
🥷 Discord: / discord
🐮 Support the channel: / neetcode
⭐ BLIND-75 PLAYLIST: • Two Sum - Leetcode 1 -...
💡 CODING SOLUTIONS: • Coding Interview Solut...
💡 DYNAMIC PROGRAMMING PLAYLIST: • House Robber - Leetco...
🌲 TREE PLAYLIST: • Invert Binary Tree - D...
💡 GRAPH PLAYLIST: • Course Schedule - Grap...
💡 BACKTRACKING PLAYLIST: • Word Search - Backtrac...
💡 LINKED LIST PLAYLIST: • Reverse Linked List - ...
💡 BINARY SEARCH PLAYLIST: • Binary Search
📚 STACK PLAYLIST: • Stack Problems
Problem Link: leetcode.com/problems/integer...
0:00 - Read the problem
1:40 - Drawing Explanation
6:25 - Coding Explanation
leetcode 12
This question was identified as an amazon interview question from here: github.com/xizhengszhang/Leet...
#amazon #interview #python
Disclosure: Some of the links above may be affiliate links, from which I may earn a small commission.

Наука

Опубликовано:

 

20 июл 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 63   
@aryanyadav3926
@aryanyadav3926 2 года назад
Great explanation! I don't even go through the discuss section if NeetCode's video is available.
@katrinak3469
@katrinak3469 2 года назад
Best explanations out there. Your videos are so succinct and well explained that I can understand any problem in about ten minutes! Got a RU-vid account just so I could subscribe and support the channel as a thank you! So thank you!!
@mengjiasings1278
@mengjiasings1278 2 года назад
Thanks for your work! I am trying to develop a habit of watching your video everyday before bed.
@priyanshu715
@priyanshu715 2 года назад
after bed will give you better result
@arunks4918
@arunks4918 2 года назад
Best in youtube. To the point, short but complete 👍
@nehascorpion
@nehascorpion Год назад
Woah! That was an outstanding explanation. Extremely clear and concise. Thanks a ton!
@LordKing13
@LordKing13 2 года назад
like+subscribed! thx for the help! I m learning a lot with your channel bro!
@DatascienceConcepts
@DatascienceConcepts 2 года назад
Such a clear explanation!
@parkboy
@parkboy 5 месяцев назад
As of Python 3.7 hashmap (dict) preserves insertion order so you don't need to use a list.
@self-learning1824
@self-learning1824 2 года назад
Thanks for the great explaination! Just a quick ques: Why did you use list instead if hashmap? I have an idea still wanted some clarification if what I thinking is right.
@jpkeys6000
@jpkeys6000 Год назад
Because you need to iterate in order. A dictionary key-value pair has no order.
@Mis_guidedz
@Mis_guidedz 7 месяцев назад
@@jpkeys6000they do in python …
@maxrivera3275
@maxrivera3275 Год назад
Hermosa solución. Simple y efectiva.
@MideStudio
@MideStudio Год назад
Thank you a lot, from France !
@imomuganda
@imomuganda Год назад
Simple and brilliant.
@gary-williams
@gary-williams 4 месяца назад
The division and modulus can be replaced with subtraction: for sym, val in reversed(symList): while num >= val: res += sym num -= val This won't perform any different (although there will be 3x as many string concatenations in the worst case (e.g., num=3333) ), but it's conceptually slightly simpler.
@andresbonelli
@andresbonelli 2 месяца назад
Cool explanation! Another possible solution: def intToRoman(self, num: int) -> str: symList = [...] # (Your symbols list) # Roman zero does not exist if num
@balu45653
@balu45653 24 дня назад
it works fine bro
@dannyhd8301
@dannyhd8301 Год назад
absolutely amazing
@adventurer2395
@adventurer2395 Год назад
Your explanations are excellent! After watching many of your videos, one suggestions I would make is better variable naming for clarity. Your variable names tend too be too concise and generic/unclear. In this video for example, "sym, val" would be clearer as "roman, decimal". I see you also use "res" a lot in many of your videos. Sometimes, I have to re-read the code a few times to keep track of what the variables mean. Other than that, awesome, and thank you so much for helping us!
@052dhirojkumarsahu9
@052dhirojkumarsahu9 Год назад
how to handle 400 , the output is "CCCC" but expected is "CD". I think To handle the case of 400, we need to add an additional condition to check if the num is equal to the current val. If that condition is true, we can directly append the symbol and subtract the value from num. This will ensure the code correctly handles cases requiring subtractive notation.
@animeshsingh4290
@animeshsingh4290 8 месяцев назад
It's already in the list of our conditions
@travelnlearn
@travelnlearn Год назад
You explained it like a peice of a cake
@nbavideos4487
@nbavideos4487 2 года назад
thank you so much
@safwan1340
@safwan1340 5 месяцев назад
Is it not mandatory to give an (!= 0) in the if statement?
@chenhaibin2010
@chenhaibin2010 2 года назад
such an elegant solution
@69savage75
@69savage75 2 года назад
Good video sir.
@jpkeys6000
@jpkeys6000 Год назад
The only thing I can say is: Thank you, thank you, thank you!!!
@Technical-zero
@Technical-zero Месяц назад
thank you for your help😀
@aaryandubey6906
@aaryandubey6906 8 месяцев назад
Good Explanation
@deadpoet4427
@deadpoet4427 2 года назад
Best 👍
@athangkulkarni8245
@athangkulkarni8245 8 месяцев назад
Can we use LinkedHashMap and iterate through it? Complexity to retrieve an element would be reduced
@parkboy
@parkboy 5 месяцев назад
Yes you can and as of Python 3.7 the hashmap preserves insertion order.
@oyeshetty
@oyeshetty 2 года назад
What about the number 1000 , it shows CDCDXCXCXX instead of M which is already in the array
@Dhanushh
@Dhanushh 2 года назад
1000 / 1000 gives count 1. which then multiplied with M gives you M alone. Then num becomes 0 due to mod operation. loop breaks
@johnniegilkerson4724
@johnniegilkerson4724 25 дней назад
ok how do you run it with no main?
@edwardteach2
@edwardteach2 2 года назад
U a Roman God
@user-mc8kz7md4o
@user-mc8kz7md4o 2 года назад
What about the number 8? In roman numerals its VIII, but if I'm not mistaken according to this code it'd be IVIV
@OGRfilms
@OGRfilms 2 года назад
Remember that we iterate through the table in reverse order. 8 would first be divided by 5, which would be divisible once (integer division), so count would be 1 for 5 and we would add 'V' and then mod by 5 to get 3, which would then be divided by 1, producing a count of 3 and adding 'I' 3 times
@user-mc8kz7md4o
@user-mc8kz7md4o 2 года назад
@@OGRfilms oh got it, thank you
@ivanleon6164
@ivanleon6164 10 месяцев назад
I have a different solución, but tours is good to me too.
@leetcodeyechimlaripython
@leetcodeyechimlaripython 4 месяца назад
thanks for your help for beginners like me 😂
@owenwu7995
@owenwu7995 10 месяцев назад
This is more math than programming
@finwwwfinwww4669
@finwwwfinwww4669 Год назад
Am i the only one in 30s and still struggling with such problems :(
@Yo-sb9st
@Yo-sb9st Год назад
This one was hard
@uqu200
@uqu200 2 года назад
for 1994 it's giving wrong answer
@rajanmaheshwari
@rajanmaheshwari 2 года назад
No, it gives the right answer i.e "MCMXCIV". However I did in Swift, but the concept is same
@sutriptaroy
@sutriptaroy 2 года назад
Yes, for 1994, it's not working
@abhineetsingh6720
@abhineetsingh6720 2 года назад
it works perfectly , just now submitted it with the same logic
@dingus2332
@dingus2332 Месяц назад
You could have avoided the complexity of reversing the list , simply making the list reverse from the start
@_Who_u_are
@_Who_u_are 3 месяца назад
how wiukd anyone know that ,he has to make a list for this problem?
@dingus2332
@dingus2332 Месяц назад
From Roman to Integer , it was pretty clear , only some cases are not considered , and those could be added here
@KTBWorld
@KTBWorld 2 года назад
I'm pretty sure that line 10 of your code "if num // val:" is unnecessary. In fact, the following few lines don't need to be nested into any conditionals at all; The line is redundant with the following line, since "count" is only going to be altered in cases where "num" is larger than "val" anyway. If you take out the conditional, the code still passes all of LeetCode's tests and accepts the submission as correct. That said, I'm still pretty new to this, so maybe there's another reason here that I'm missing. Would adding that conditional allow the program to run faster, as the processor wouldn't need to run through the following lines for "value" values that aren't going to change the result? LeetCode doesn't give noticeably different CPU usages or speeds for the two different versions of the code, but I can imagine that maybe this is something that would only be an issue in longer and more complex software.
@JOHNSMITH-ve3rq
@JOHNSMITH-ve3rq Год назад
Why nest these solutions inside a class? Why not just make the scope the py script?
@KeepCoding69
@KeepCoding69 Год назад
Because u have to submit this code in leetcode by nesting it inside a class. That's how leetcode works
@JashSingh-bv5ge
@JashSingh-bv5ge 6 месяцев назад
im too dumb to code
@HimanshuKumar_24
@HimanshuKumar_24 3 месяца назад
Can someone please type that list of lists for me, I'll Gpay 20 Rs.
@raghavendras8866
@raghavendras8866 Месяц назад
Bruh 😂
@koolkataustin2961
@koolkataustin2961 4 месяца назад
LOL
@tsunningwah3471
@tsunningwah3471 Год назад
sexjhvhj
@karthick...
@karthick... 7 месяцев назад
I hate python bcz i am C++ coder
@firozkamdar6735
@firozkamdar6735 4 месяца назад
Agreed
Далее
Roman to Integer - Leetcode 13 - Python
7:57
Просмотров 160 тыс.
Integer to Roman | Leetcode #12
17:34
Просмотров 37 тыс.
skibidi toilet 76 (full episode)
08:11
Просмотров 8 млн
Parents' Breakfast Rescue Mission for Laptops
00:28
АРЕХ ПОЙМАЛ БЕЛКУ ОТ ИГРЫ ВП
15:01
ZigZag Conversion - Leetcode 6 - Python
12:46
Просмотров 93 тыс.
8 patterns to solve 80% Leetcode problems
7:30
Просмотров 255 тыс.
Product of Array Except Self - Leetcode 238 - Python
11:54
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
5 Useful F-String Tricks In Python
10:02
Просмотров 279 тыс.
Jump Game II - Greedy - Leetcode 45 - Python
11:58
Просмотров 177 тыс.
APPLE дают это нам БЕСПЛАТНО!
1:01
Просмотров 659 тыс.
Choose a phone for your mom
0:20
Просмотров 7 млн