Integer to Roman -(Amazon, Facebook, Microsoft, Twitter, Apple, Google..): Explanation ➕ Live Coding

  Рет қаралды 11,220

codestorywithMIK

codestorywithMIK

Күн бұрын

Пікірлер: 21
@chetnarai407
@chetnarai407 3 ай бұрын
i am so sure that now anytime i see this or any similar question, this approach will save my time sm... thank you
@thaman701
@thaman701 9 ай бұрын
Nicely explained brother ❤
@ShivamGupta-cx3hy
@ShivamGupta-cx3hy 2 жыл бұрын
understood clearly
@codestorywithMIK
@codestorywithMIK 2 жыл бұрын
Glad i could help. Appreciate your kind words ❤️
@iamnottech8918
@iamnottech8918 3 ай бұрын
u are a life saver....
@069_bhanuprasadgoud3
@069_bhanuprasadgoud3 Жыл бұрын
good explaination
@codestorywithMIK
@codestorywithMIK Жыл бұрын
Thank you ❤️😇
@wearevacationuncoverers
@wearevacationuncoverers 9 ай бұрын
crystal clear. Thanks a lot
@itsme9877
@itsme9877 6 ай бұрын
@Saurabh_91
@Saurabh_91 9 ай бұрын
k videos
@rishabhverma6318
@rishabhverma6318 Жыл бұрын
string intToRoman(int num) { string romanSymbols[] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; int values[] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; string ans=""; // jb convert krte h to sbse bda number choose krte hai for(int i=0;i=values[i]){ ans+=romanSymbols[i]; num-=values[i]; } } return ans; }
@anmolbansal4009
@anmolbansal4009 4 ай бұрын
why we used static before the vector?? what does it do? code is running fine without it also....why we use it then?
@syedsuffiyan4747
@syedsuffiyan4747 Ай бұрын
it wont get initialized continuosly since all values are constant in the array so we use static keyword
@vinniverma469
@vinniverma469 3 күн бұрын
i have a better approch i used a custom hash (becuase hashmap does not gaurentee order which is necessary for this ques ) string intToRoman(int num) { vector roman = { {1000, "M"}, {900, "CM"}, {500, "D"}, {400, "CD"}, {100, "C"}, {90, "XC"}, {50, "L"}, {40, "XL"}, {10, "X"}, {9, "IX"}, {5, "V"}, {4, "IV"}, {1, "I"} }; string res=""; while(num>0){ for( auto & x:roman){ int times=num/x.first; while(times>0){ res+=x.second; times--; } num=num%x.first; } } return res; }
@aashukumar6365
@aashukumar6365 3 ай бұрын
tc and sc?
@kallabhalu6006
@kallabhalu6006 9 ай бұрын
One confusion, why didnt we use hashmap to store values as it is more intutive to store mapping of numbers to character. Please Answer
@jewelchakraborty9717
@jewelchakraborty9717 8 ай бұрын
My suggestion is to use TreeMap in descending order instead of normal hashmap
@mma-dost
@mma-dost 9 ай бұрын
int romanToInt(string s) { unordered_map mp; mp['I'] = 1; mp['V'] = 5; mp['X'] = 10; mp['L'] = 50; mp['C'] = 100; mp['D'] = 500; mp['M'] = 1000; int n = s.length(); int prev = 0; int number = 0; for(int i = n-1; i > -1; i--){ if(prev > mp[s[i]]) number = number - mp[s[i]]; else number = number + mp[s[i]]; prev = mp[s[i]]; } return number; } Is this solution, okay? Wrote this myself looks good to me. If you can correct something guys, please reply.
@euphoria176_5
@euphoria176_5 Ай бұрын
This is roman to int and not int to roman
@basujain8928
@basujain8928 4 ай бұрын
we can also put continue
Roman To Integer | Leetcode 13
10:21
Techdose
Рет қаралды 13 М.
This Game Is Wild...
00:19
MrBeast
Рет қаралды 187 МЛН
How many people are in the changing room? #devil #lilith #funny #shorts
00:39
Roman to Integer - Leetcode 13 - Python
7:57
NeetCode
Рет қаралды 179 М.
Integer to Roman | Leetcode #12
17:34
Techdose
Рет қаралды 44 М.
Integer to Roman - Leetcode 12 - Python
9:43
NeetCode
Рет қаралды 77 М.
NVIDIA’s New AI: Stunning Voice Generator!
6:21
Two Minute Papers
Рет қаралды 80 М.
GFG POTD: 04/10/2023 | Roman Number to Integer | Problem of the Day GeeksforGeeks
6:24
This Game Is Wild...
00:19
MrBeast
Рет қаралды 187 МЛН