Тёмный

Roman to Integer | Leetcode -13 | Algorithms Made Easy 

Algorithms Made Easy
Подписаться 39 тыс.
Просмотров 142 тыс.
50% 1

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

 

26 окт 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 107   
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure ] : ru-vid.com/group/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls ✅✅✅[ Graphs Data Structure ] : ru-vid.com/group/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C ✅✅✅[ January Leetcoding Challenge ] : ru-vid.com/group/PLJtzaiEpVo2wCalBcRcNjXQ0C6ku3dRkn ✅✅✅[ December Leetcoding Challenge ] : ru-vid.com/group/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA ✅✅✅[ November Leetcoding Challenge ] : ru-vid.com/group/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e ✅✅✅[ August Leetcoding Challenge ] : ru-vid.com/group/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe ✅✅✅July Leetcoding challenges: ru-vid.com/group/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC- ✅✅✅June Leetcoding challenges: ru-vid.com/group/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG ✅✅✅May Leetcoding challenges: ru-vid.com/group/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e ✅✅✅Cracking the Coding Interview - Unique String: ru-vid.com/group/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
@nikhiltiwari20
@nikhiltiwari20 Год назад
Please make a series od dsa problem and solution explaination video.
@ShrutiSingh-l6h
@ShrutiSingh-l6h 7 месяцев назад
None of my code run in my leetcode
@pammcm4542
@pammcm4542 2 года назад
Best explanation for this problem on RU-vid. Thanks.
@stephaniemichelle4604
@stephaniemichelle4604 2 года назад
wow! I never thought of going reverse. I like your explanation a lot! I was using a switch case with repetitive code.
@aaqibjavedz2569
@aaqibjavedz2569 Год назад
Yeah me neither, I would always start from left -> right and add the numbers.
@mriduljain1981
@mriduljain1981 Год назад
@@aaqibjavedz2569 you could do it in that way too
@bostonlights2749
@bostonlights2749 2 года назад
Good Editing, Clear Voice and clean solution. I've subscribed
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 года назад
Thanks !!
@shubhankarmane3172
@shubhankarmane3172 3 года назад
This channel provides the best solutions. Keep up the good work.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
Thanks Shubhankar!!! 🙂
@SunilSharma-mb2kf
@SunilSharma-mb2kf 2 года назад
Just wow. I coded this solution from left to right, but it becomes complicated and lots of conditional statements. Right to left is awesome. Thanks.
@victorvega2014
@victorvega2014 2 года назад
I think it is almost the same. const s = 'LVIII' let result = 0 const dict = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 }; let arr = s.split(''); for (var i = 0; i < arr.length; i++) { if (dict[arr[i]] < dict[arr[i + 1]]) { result += (dict[arr[i]]) * (-1) } else { result += dict[arr[i]] } } return(result)
@Ziggy0120
@Ziggy0120 3 года назад
thanks! I have been stuck on this problem for a while now. you made it make a lot of sense!
@RohitKumar-tk3df
@RohitKumar-tk3df 2 года назад
The perfect Channel name for the perfect Video. Algorithms made easy.....❤❤❤❤❤
@aastikofficial6100
@aastikofficial6100 10 месяцев назад
Very easy and simple approach and well explained crystal clear i used to watch this channel for more videos .Thank you 🌟🌟
@soumyadipbhowmik2220
@soumyadipbhowmik2220 2 года назад
Just watched the video. This is the kind of explanation I was looking for. Subscribed.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Glad you enjoyed it!
@karunasagarks5228
@karunasagarks5228 2 года назад
Really a great video, we need more such Leetcode video solutions! Thank you very much for this one.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Glad you enjoyed it!
@jatinkumar4410
@jatinkumar4410 8 месяцев назад
Your presentation visuals are amazing. Thanks for the content
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 7 месяцев назад
Thank you!!
@madhukar0721
@madhukar0721 2 года назад
we can go forward to it also takes O(n) time complexity Ping me if u need the code or a Hint
@tasneemayham974
@tasneemayham974 Год назад
AMAZING CONTENT!! SIMPLE AND PERFECT!!!!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Thank you!!
@k23j43
@k23j43 9 дней назад
I have a question, in LeetCode all code should be inside the function? Even the const Map that will be use multiple times? Can I put this map in the Solution class instead?
@kunalkheeva
@kunalkheeva 2 года назад
the perfect explanation and in just 5 minutes!! Thank you.
@justkeepstretching2037
@justkeepstretching2037 3 года назад
What's better to use in this case, a hashmap or a switch statement?
@sudipta_pradhan
@sudipta_pradhan 2 года назад
hashmap
@gautamjh
@gautamjh 2 года назад
@@sudipta_pradhan Why? Arent we using extra space if we use hashmap?
@julianodesousacervelin143
@julianodesousacervelin143 2 года назад
@@gautamjh the hashmap doesn't grow, it's constant. It could even be static, therefore, space complexity is still O(1), isn't it?
@sidharthmalhotra7874
@sidharthmalhotra7874 Год назад
you made it easier to understand..really great
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Glad it helped!
@maheshjindal2622
@maheshjindal2622 2 года назад
Clean, Crisp, to the point code
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Appreciate that
@molyoxide8358
@molyoxide8358 Год назад
Thanks for creating this presentation and explanation.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Thank you so much!! Do checkout our latest videos too!! 👍👍
@fashionbox3072
@fashionbox3072 2 года назад
it shows error like this : Line 4: Char 13: error: use of undeclared identifier 'Character' Map map = new HashMap();
@rishabhagrawal8938
@rishabhagrawal8938 Год назад
Same
@vaibhavsharmaqa
@vaibhavsharmaqa Год назад
thanks for this!! One query , how can we handle -ve cases like below? ("IV", "IIII") ("IX", "VIIII") ("XL", "XXXX") ("XC", "LXXXX") ("CD", "CCCC") ("CM", "DCCCC")
@neerajjatwa2048
@neerajjatwa2048 3 месяца назад
C++ code: class Solution { public: int romanToInt(string s) { map map; map['I']=1; map['V']=5; map['X']=10; map['L']=50; map['C']=100; map['D']=500; map['M']=1000; int result = map[s[s.length()-1]]; for(int i =s.length()-2;i>=0;i--){ if(map[s[i]]
@SubasriM-mk9hj
@SubasriM-mk9hj 2 месяца назад
Perfect explanation mam👏
@dayakard212
@dayakard212 2 года назад
Mam u kept the solution clean and easy.
@bikkysharma7253
@bikkysharma7253 2 года назад
right to left approach makes it very easy ,thanks
@imshivendra
@imshivendra 2 года назад
I don't know why but your code is giving wrong output on geeksforgeeks ide
@ashishrao1789
@ashishrao1789 Год назад
In 3rd line, it is not Map and character C shld be capital ..It is HashMap=new HashMap();
@reniside4357
@reniside4357 Год назад
it is really hard to cope pls how do you guys get so good at understanding stuff like this, how does one even learn programming to understand better.
@-Corvo_Attano
@-Corvo_Attano 2 года назад
Better than other explanation videos :) Thank you
@ManmohanBhardwaj-ft2hu
@ManmohanBhardwaj-ft2hu 11 месяцев назад
Explanation is good 👍but help me for program not working showing this Line 4: Char 13: error: use of undeclared identifier 'character' Mapmap=new HashMap();
@vickmaproductions
@vickmaproductions 9 месяцев назад
Use capital C in the word Character
@amanprajapati3417
@amanprajapati3417 2 года назад
you just gave me the new perespective to the question Thank you
@cstechexpert5750
@cstechexpert5750 Год назад
what if i pass IIX as there is no validation can you please explain
@MohammadWasimKhan
@MohammadWasimKhan 11 месяцев назад
Great explanation. Thankyou so much.😊
@israelayoade
@israelayoade 2 года назад
Bravo!!! Am clapping.
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 года назад
Thanks !!
@imshivendra
@imshivendra 2 года назад
I don't know why but your code is giving wrong output on geeksforgeeks ide. And one more thing why you are taking s.length()-1 why not s.length() ?
@ShubhamSingh-kx4ov
@ShubhamSingh-kx4ov Год назад
great simple and perfect
@codetech-01
@codetech-01 2 года назад
easy to understand explanation. Thank you
@dharmendraudawat
@dharmendraudawat 2 года назад
nicely explained
@alayparikh5622
@alayparikh5622 3 года назад
Explanation and everything was good. But next time please dont cover up your mistakes. We all are humans (Proof: Check 3rd line of the code at 4:36 and 4:38)
@ayushsinghrathore360
@ayushsinghrathore360 Год назад
Yeh Smart 🤓🤣
@somsk56
@somsk56 Год назад
Is it possible ? without using Map ?
@sharad3877
@sharad3877 Год назад
how can we solve it, without using auxillary space?
@rakshakannu5044
@rakshakannu5044 3 года назад
very well explained!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
Thanks !
@vasanthakumars20me3
@vasanthakumars20me3 2 года назад
Hi mam, i am facing this issue while programming the roman to integer (Syntax Error: invalid syntax ^ Class Solution { Line 1 (Solution.py)) full program I was did:- Class Solution { public int romanToInt(string, s){ Map map = new Hashmap(); map.put("I" , 1); map.put("V" , 5); map.put("X" , 10); map.put("L" , 50); map.put("C" , 10); map.put("D" , 500); map.put("M" , 1000); int res = map.get(s.charAt(s.length()-1)); for (int i = s.length()-2; i >=0; i--) { if (map.get(s.chartAt(i)) < map.get (s.charAt(i+1))){ res-=map.get(s.charAt(i)); } else{ res+=map.get(s.charAt(i)); } } return res; } } Do we have a any method to resolve it?
@ashutoshkabir1657
@ashutoshkabir1657 2 года назад
Try to use capital c in character not small
@tcoa11pavanrengade34
@tcoa11pavanrengade34 Год назад
Mapmap = new HashMap(); map.put('I' , 1); map.put('V' , 5); map.put('X' , 10); map.put('L' , 50); map.put('C' , 100); map.put('D' , 500); map.put('M' , 1000); int res = map.get(s.charAt(s.length()-1)); for (int i = s.length()-2; i >=0; i--) { if (map.get(s.charAt(i)) < map.get (s.charAt(i+1))){ res-=map.get(s.charAt(i)); } else{ res+=map.get(s.charAt(i)); } } return res; Use this code, This is edited version of your code.
@vidhikansara7103
@vidhikansara7103 3 года назад
very nice and easy solution thank you
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
Thanks !!
@akami_007
@akami_007 3 года назад
Thanks a lot mam, this really helped for me !
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
Happy to help!!
@siva.....45
@siva.....45 Год назад
why we traverse the string from the end???
@vijaysukumarv3512
@vijaysukumarv3512 2 года назад
Super explained mam.
@mashapoguajay3322
@mashapoguajay3322 Год назад
mam y we have to perform only friom right to left why nit from startin g index
@arshiyaanjum873
@arshiyaanjum873 2 года назад
why should we go from right to left?plzz
@bhuppidhamii
@bhuppidhamii Год назад
thank you.....
@KAVIBHARATHIP-i5h
@KAVIBHARATHIP-i5h Год назад
why we are applying a map .why can't put the values in a single line? like (I=1,V=5,C=100,M=1000) LIKE THIS
@FailReviewYT
@FailReviewYT 6 месяцев назад
how that mcmxciv come?
@PrabhatListing
@PrabhatListing 9 месяцев назад
how can we convert roman numbers into numbers(counting 1,2,3) in word document, I tried but not found solution if u have plz share
@ascar66
@ascar66 2 месяца назад
Your solution is 5 ms. This solution is 4 ms. Which one is better to choose? public int romanToInt(String s) { int sum = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) == 'I') sum += 1; if (s.charAt(i) == 'V') sum += 5; if (s.charAt(i) == 'X') sum += 10; if (s.charAt(i) == 'L') sum += 50; if (s.charAt(i) == 'C') sum += 100; if (s.charAt(i) == 'D') sum += 500; if (s.charAt(i) == 'M') sum += 1000; if ( i != 0) { if (s.charAt(i) == 'V' && s.charAt(i - 1) == 'I') sum -=2; if (s.charAt(i) == 'X' && s.charAt(i - 1) == 'I') sum -=2; if (s.charAt(i) == 'L' && s.charAt(i - 1) == 'X') sum -=20; if (s.charAt(i) == 'C' && s.charAt(i - 1) == 'X') sum -=20; if (s.charAt(i) == 'D' && s.charAt(i - 1) == 'C') sum -=200; if (s.charAt(i) == 'M' && s.charAt(i - 1) == 'C') sum -=200; } } return sum; }
@nitin4598
@nitin4598 2 года назад
Nice explanation
@arnabchakraborty246
@arnabchakraborty246 2 года назад
Thank you very much
@syedhabeebuddin101
@syedhabeebuddin101 3 года назад
Thanks !
@rosonerri-faithful
@rosonerri-faithful 3 года назад
Solid Explanation!
@vigneshbalamurugan6537
@vigneshbalamurugan6537 2 года назад
Very useful 🙂
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 года назад
Glad you liked it !!
@poojamaheshwari748
@poojamaheshwari748 3 года назад
best explanation
@tasneemayham974
@tasneemayham974 Год назад
May anyone please tell me why does my code always ignore the last element? HashMap map = new HashMap(); map.put('I', 1); map.put('V', 5); map.put('X', 10); map.put('L', 50); map.put('C', 100); map.put('D', 500); map.put('M', 1000); int total =0; for(int i=0; i
@gaurabsingh2760
@gaurabsingh2760 Год назад
Because i does not reaches the last position u should add the corresponding integer value of last character and then your answer will be correct
@rohitnegi6463
@rohitnegi6463 2 года назад
Thanks di!!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 2 года назад
most welcome!!
@ripplesr5655
@ripplesr5655 2 года назад
Bro, plz tell me how do I become good at solving these like you? 😭 I Suck more than my life!
@yilinlian7995
@yilinlian7995 2 года назад
thank you
@hahadarsh
@hahadarsh Год назад
I am your 1000th like, haha!
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy Год назад
Thanks for the like.
@chethan6667k
@chethan6667k 8 месяцев назад
is this an easy ques? oh ma god
@RAUSHANKUMAR-iq4yj
@RAUSHANKUMAR-iq4yj 2 года назад
Thanks❤🌹🙏 a lot😊
@saiteja335
@saiteja335 2 года назад
awesome
@CRamPrasannaCV
@CRamPrasannaCV 3 года назад
Understood :-)
@shubrochakroborty5918
@shubrochakroborty5918 2 года назад
just wow
@shreyamatade409
@shreyamatade409 2 года назад
C++ code pls
@yashjain93
@yashjain93 2 года назад
class Solution { public: int romanToInt(string s) { int ans=0; mapmp; mp.insert(make_pair('I',1)); mp.insert(make_pair('V',5)); mp.insert(make_pair('X',10)); mp.insert(make_pair('L',50)); mp.insert(make_pair('C',100)); mp.insert(make_pair('D',500)); mp.insert(make_pair('M',1000)); for(int i=s.length()-2; i>=0;i--){ if(mp[s[i]]
@shivamswaraj6456
@shivamswaraj6456 3 года назад
Thank you so much
@AlgorithmsMadeEasy
@AlgorithmsMadeEasy 3 года назад
Happy to help!!
@suhaskadu1358
@suhaskadu1358 2 года назад
nice explanation
Далее
Integer to Roman | Leetcode #12
17:34
Просмотров 44 тыс.
Three NEW MAPS in Update 0.31.0 Nightmare | Standoff 2
01:48
I Solved 100 LeetCode Problems
13:11
Просмотров 166 тыс.
5 Simple Steps for Solving Any Recursive Problem
21:03
Roman To Integer | Leetcode 13
10:21
Просмотров 13 тыс.
Big-O Notation - For Coding Interviews
20:38
Просмотров 498 тыс.