String to Integer atoi 🔥| Leetcode 8 | String

  Рет қаралды 45,168

Ayushi Sharma

Ayushi Sharma

Күн бұрын

Пікірлер: 160
@selvarajan4062
@selvarajan4062 2 ай бұрын
I am newbie , have two doubts. 1) why we using long to define ans 2)in the line ans=ans*10+s[i]-' 0 ' what is purpose of this one'0' I hope you will explain it😢😢
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
hi sure, :) so see, 1. if we do not use long, and we use int, we get signed overflow error Line 23: Char 23: runtime error: signed integer overflow: 912834723 * 10 cannot be represented in type 'int' (solution.cpp) SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior solution.cpp:23:23 this is because ans variable may add up to values which go beyond specific integer range, so we use long :) 2. so, the expression s[i] - '0' is a common way to convert a character representing a digit to its corresponding integer value. for eg. If s[i] is '5', its ASCII value is 53. Subtracting the ASCII value of '0' (48) from it gives 53 - 48 = 5, which is the integer representation of the digit.
@selvarajan4062
@selvarajan4062 2 ай бұрын
@@AyushiSharmaDSA omg thanks mam 👍 . 😊
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
@@selvarajan4062 no worries :)
@tanujarora4906
@tanujarora4906 Жыл бұрын
This Question is king of edge cases.
@codeman0017
@codeman0017 10 ай бұрын
yes
@adityatiwari2488
@adityatiwari2488 2 ай бұрын
True
@susmitapatil4847
@susmitapatil4847 Жыл бұрын
I saw multiple video solutions but no one able to clear this much. Good job. Keep doing good work. Thanks!!
@valiz2628
@valiz2628 Жыл бұрын
ok
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
thank you so much :)
@OatsAurCode
@OatsAurCode Жыл бұрын
Videos are helpful. Just adding the python version in case anyone needs class Solution: def myAtoi(self, str: str) -> int: # for removing white spaces str = str.strip() if not str: return 0 sign = -1 if str[0] == '-' else 1 str = str[1:] if str[0] in ['-', '+'] else str res = 0 for char in str: if not char.isdigit(): break res = res * 10 + int(char) if res * sign >= 2**31 - 1: return 2**31 - 1 if res * sign
@tusharnain6652
@tusharnain6652 2 жыл бұрын
You don't know how happy i am after seeing your video in search result...every time.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you so much Tushar, means a lot😊😊
@hemantsharma9247
@hemantsharma9247 2 ай бұрын
Clear explanation, every second was worth it!!
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
thank you so much 😊🙌
@hrithikrudra4292
@hrithikrudra4292 2 жыл бұрын
Detailed explanation for each case...!!Wow
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you :) glad it was helpful
@sudhirjaiswal4109
@sudhirjaiswal4109 10 күн бұрын
Thank you so much ....your way of explanation is awesome☺
@raviashwin1157
@raviashwin1157 2 жыл бұрын
I love your voice❤️,such a nice explanation keep uploading quality content.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you, I will :)
@user-ee1hg
@user-ee1hg 4 ай бұрын
really great explanation !!!! found this after watching some tuff explaining videos....keep doing well....
@AyushiSharmaDSA
@AyushiSharmaDSA 4 ай бұрын
thank you, glad you liked it :)
@amarjeetkumarsingh733
@amarjeetkumarsingh733 Жыл бұрын
Best explanation among all videos of this prob I have ever seen.....Thank You
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Thank you so much Amarjeet, glad it was helpful 🤩😊
@ChandraShekhar-by3cd
@ChandraShekhar-by3cd 2 жыл бұрын
Crystal clear Explanation. Thanks! Happy Makar Sankranti ! 😇
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Chandra, and Happy Makar Sakranti to you too :)
@SubhasisNandaYoganeer
@SubhasisNandaYoganeer 2 жыл бұрын
Awesome explanation thanks for providing java solution as well means a lot you're an inspiration
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Subhasis 😄
@saikumargatla4706
@saikumargatla4706 Жыл бұрын
Explained very well
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
thank you :)
@vineetjadhav1785
@vineetjadhav1785 2 ай бұрын
Great Explaination Ayushi ❤❤👋👋
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
thank you 🤗
@AshwaniKumar-im6zb
@AshwaniKumar-im6zb 2 жыл бұрын
Thanks Ayushi for your time.
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome Ashwani, glad it was helpful :)
@ishangujarathi10
@ishangujarathi10 Жыл бұрын
thankyou so much for such an easy explanation of this problem
@bharathKumar-or6gd
@bharathKumar-or6gd 3 ай бұрын
Thank you Ayushi, Good explantion
@AyushiSharmaDSA
@AyushiSharmaDSA 3 ай бұрын
thank you, glad you liked it :)
@hitmanop4078
@hitmanop4078 3 ай бұрын
she's looking like she's solving this for like days (might be because of all the edge cases) REAL KODER
@AyushiSharmaDSA
@AyushiSharmaDSA 3 ай бұрын
thank you :)
@allmovies2473
@allmovies2473 4 ай бұрын
Thanks Ayushi for this awesome explanation❤❤
@allmovies2473
@allmovies2473 4 ай бұрын
@Ayushi Sharma
@AyushiSharmaDSA
@AyushiSharmaDSA 4 ай бұрын
@@allmovies2473 welcome, glad it was helpful ❤️😊
@ankushladani496
@ankushladani496 2 жыл бұрын
Good Explaination...
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Thanks 😊
@abhaythakur2597
@abhaythakur2597 9 ай бұрын
very well explained
@its_sagar371
@its_sagar371 8 күн бұрын
why i got this error " module 'string' has no attribute 'letters'" in leetcode. Below is my code int myAtoi(string s) { if(s.length()==0) return 0; int i=0; if(i
@realAB459
@realAB459 2 жыл бұрын
I just opened youtube thinking that today's leetcode video has been uploaded here.😁
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
🥺🥺😊
@sayanraha77
@sayanraha77 Жыл бұрын
Very nice,crisp and intutive approach didi thanks a lot
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Most welcome 😊
@MAYANKSINGH-mf2ll
@MAYANKSINGH-mf2ll 10 ай бұрын
thanks Maam for the crystal and clear explanation 👏👏
@AyushiSharmaDSA
@AyushiSharmaDSA 6 ай бұрын
thank you, glad it was helpful :)
@samyakagarwal9565
@samyakagarwal9565 5 ай бұрын
very nice explanation ....
@AyushiSharmaDSA
@AyushiSharmaDSA 5 ай бұрын
Thank you :)
@sadhgurumeditationmusic531
@sadhgurumeditationmusic531 2 жыл бұрын
Thanks Ayushi ,amazing explaination
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome, glad it was helpful 😊
@crazeeealgorithms3236
@crazeeealgorithms3236 11 ай бұрын
Great Explanation!!
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
glad you found it helpful :)
@SuperWhatusername
@SuperWhatusername 2 жыл бұрын
Thanks Ayushi. Covered everything
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome, glad it was helpful :)
@vineetkumar2899
@vineetkumar2899 Жыл бұрын
Thanks a lot for this awesome explanation.
@Supercool7042
@Supercool7042 2 жыл бұрын
well explained !! thanks
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Thanks 😊
@anurag_ad_01
@anurag_ad_01 Жыл бұрын
awesome solution
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
thank you :)
@yobro7322
@yobro7322 2 жыл бұрын
very nice explanation
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you 😊
@Surya-np1bb
@Surya-np1bb 2 жыл бұрын
Thanks, these videos are really helpful!
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Welcome Surya, glad they are helpful 🤗
@ankithshetty6005
@ankithshetty6005 4 ай бұрын
🎯 Key points for quick navigation: 00:02 *Handle leading whitespace* 00:42 *Convert string to integer* 01:25 *Check sign (positive/negative)* 02:08 *Read until non-digit* Made with HARPA AI
@anshumaan1024
@anshumaan1024 11 ай бұрын
*line 24 & 25* should include equal to also , like this if( sign==-1 && -1*ans
@mountain_guest2174
@mountain_guest2174 9 ай бұрын
no, the problem statement condition states strictly out of range.
@NavinVenkat-t4d
@NavinVenkat-t4d 13 күн бұрын
Thanks Ayushi
@AyushiSharmaDSA
@AyushiSharmaDSA 12 күн бұрын
welcome :)
@OatsAurCode
@OatsAurCode Жыл бұрын
Explanation is best. Just wanted to know is cp mandatory for coding rounds of product based companies. If yes then how to begin.
@sufiyaniqbal5280
@sufiyaniqbal5280 2 жыл бұрын
thanks for the explanation mam ,respect your efforts
@software3089
@software3089 2 жыл бұрын
Superb explanation !
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you 😊
@Useriddead7
@Useriddead7 23 күн бұрын
you are awesomeee....but at the same time, after seeing your Github, feeling like i'm just way too far from it🙂
@AyushiSharmaDSA
@AyushiSharmaDSA 14 күн бұрын
thank you 🤗
@rashidalikhan3613
@rashidalikhan3613 2 жыл бұрын
Clear explanation.. well done 👍
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Rashid, glad it was helpful :)
@the_ved11
@the_ved11 9 ай бұрын
Great Job!
@AyushiSharmaDSA
@AyushiSharmaDSA 8 ай бұрын
Thanks!
@chiragjain1424
@chiragjain1424 2 жыл бұрын
i think in second while loop , it should be s[i]==' ' instead of s[0]==' ' .
@ece-projects3969
@ece-projects3969 2 жыл бұрын
bro she change the string from original s to s.substr(i) so it from starting that's why it is s[0]
@rishiraj2548
@rishiraj2548 9 ай бұрын
Great thanks
@sruthimajhi5610
@sruthimajhi5610 2 ай бұрын
Thanks a lot!
@AyushiSharmaDSA
@AyushiSharmaDSA 2 ай бұрын
You’re welcome ☺️
@ecs185_shaileshbharti3
@ecs185_shaileshbharti3 2 жыл бұрын
💯🔥 Reach ++;
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you :)
@rahulkumar4003
@rahulkumar4003 2 жыл бұрын
very nicely explained❤
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Rahul :)
@amitkumarchoudhary9008
@amitkumarchoudhary9008 2 жыл бұрын
Mam your voice ❤️❤️
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thanks Amit 😊
@Chirag12390
@Chirag12390 7 ай бұрын
Big fan ❤❤❤
@AyushiSharmaDSA
@AyushiSharmaDSA 6 ай бұрын
I am too 😛😁
@Chirag12390
@Chirag12390 6 ай бұрын
@@AyushiSharmaDSA 😁😁😁😁
@yogeshyts
@yogeshyts 2 жыл бұрын
home theather pe lga ke suni h ye video itna acha mic h tumhara
@indian_tech6185
@indian_tech6185 5 ай бұрын
@dipanshu apka bohottt bdaa fan h
@AyushiSharmaDSA
@AyushiSharmaDSA 5 ай бұрын
ohh, agar yahi dipanshu bolta to zyada acha lgta 😜 btw thank you for letting me know :)
@indian_tech6185
@indian_tech6185 5 ай бұрын
@@AyushiSharmaDSA 1 min usko btata hu wo krega comment 😂
@SavitarOP
@SavitarOP 2 жыл бұрын
OP Solution
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thank you Saurabh :)
@sagardas4218
@sagardas4218 9 ай бұрын
Thank you
@AyushiSharmaDSA
@AyushiSharmaDSA 8 ай бұрын
You're welcome
@SarojYadav-h2z
@SarojYadav-h2z Жыл бұрын
Thanks mam 😌
@markphilip3982
@markphilip3982 Жыл бұрын
you earned a sub
@AyushiSharmaDSA
@AyushiSharmaDSA 6 ай бұрын
thank you, glad it was helpful :)
@SRV.77
@SRV.77 2 жыл бұрын
Thank you dI
@shaikaftabahmed9666
@shaikaftabahmed9666 Жыл бұрын
you earned a sub!!!!
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Thank you 😊
@rajaranjith5151
@rajaranjith5151 Жыл бұрын
just tell me what can I do to say just like you did, that this is very easy peoblem?
@Vishaljoshi-uo6yc
@Vishaljoshi-uo6yc 2 жыл бұрын
Good JOb
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Thanks Vishal :)
@Abhay14
@Abhay14 Жыл бұрын
thanks didi
@kidoo1567
@kidoo1567 Жыл бұрын
Thanx Sharma
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
Welcome :)
@mahadeolokhande2996
@mahadeolokhande2996 10 ай бұрын
Tnq u 🎉❤
@manojgmanojg9600
@manojgmanojg9600 2 жыл бұрын
Wonderful Explanation ,I understand the each and every line.
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Thanks Manoj 🤗
@reenayadav8468
@reenayadav8468 2 жыл бұрын
Abhi me apka he vedio dekh rahi thi😄
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
🥺🥺🥺🙌🏻
@reenayadav8468
@reenayadav8468 2 жыл бұрын
@@AyushiSharmaDSA and thank you for providing java code link🤩
@codinghub5540
@codinghub5540 Жыл бұрын
Please, before uploading the video check it . Sometime solution is hide behind your face screen. Otherwise it's good . Thank for explanation 🙂.
@AyushiSharmaDSA
@AyushiSharmaDSA Жыл бұрын
Yeah, so sorry for this, will take care next time :)
@kumarpatra691
@kumarpatra691 2 жыл бұрын
Can I get all your java coding session in one place..?So,I can practice in order.
@replyplz8874
@replyplz8874 2 жыл бұрын
Why are checking again s[0]==‘ ‘ in 2 nd while loop?
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Because there might be a space after digit or anywhere in middle, for eg : " 234 6hhs", in this test case there is space after 4 , so we will break after that and output will be 234
@replyplz8874
@replyplz8874 2 жыл бұрын
@@AyushiSharmaDSA Thanks for ur reply. I mean does isdigit function doesn’t consider spaces?
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
@@replyplz8874 No, it doesn't consider spaces, it will return true if there is digit otherwise false
@nehalpradhan2229
@nehalpradhan2229 Жыл бұрын
@@AyushiSharmaDSA why s[0] == ' ' instead of s[i] == ' ' ??
@BreezyBr0
@BreezyBr0 Жыл бұрын
what about alphabets ??
@Electrocode_gk
@Electrocode_gk 8 ай бұрын
above while loop not removing spaces
@it_91_vaibkhare20
@it_91_vaibkhare20 2 жыл бұрын
If after trim string become empty then how it will check for sign
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
trim only removes the leading whitespaces, if string has digits, those will not be removed :)
@sourjadhar9332
@sourjadhar9332 Жыл бұрын
1030 cases are running out of 1084 cases...is it true for you as well?bcz i can't find any error in my code
@balavardhanreddy8581
@balavardhanreddy8581 Жыл бұрын
whats the meaning of s[i]-'0'? will it convert to int?
@shubham_v
@shubham_v Жыл бұрын
Yes
@vitaminprotein2217
@vitaminprotein2217 2 жыл бұрын
why cant we do this 😂 return stoi(s); although all cases are accepted but in submission it it throwing RTE lol
@ManjeetSingh-fr3ue
@ManjeetSingh-fr3ue Жыл бұрын
please provide reccursive solution of this question
@pranavkumarparihar1397
@pranavkumarparihar1397 2 жыл бұрын
Thanks di
@AyushiSharmaDSA
@AyushiSharmaDSA 2 жыл бұрын
Welcome Pranav, glad it was helpful :)
@Omkar-fg4ws
@Omkar-fg4ws 4 ай бұрын
ooooooo cutieeee🥲🙂🙂
@ShahNawaz-cx3pi
@ShahNawaz-cx3pi Ай бұрын
Working code on Leetcode , with updated tests class Solution { public: int myAtoi(string s) { int len = s.size(); int i = 0; int sign = 1; // postive long long int res = 0; while(i
@AyushiSharmaDSA
@AyushiSharmaDSA Ай бұрын
thanks for sharing ur code :)
@Anurag-fk3op
@Anurag-fk3op 6 ай бұрын
like who is here after passing all the given test cases
@tejbahadurverma7256
@tejbahadurverma7256 5 ай бұрын
Jab phli bar dekha toh lga ki aray yaar bachi pdha rhi hai phir LinkedIn pe naam search kiya toh Walmart phir Microsoft 😂😂😂
@AyushiSharmaDSA
@AyushiSharmaDSA 4 ай бұрын
hehe, 😂😂
@shachisinghal8856
@shachisinghal8856 Жыл бұрын
This quest should have been in HARDof leetcode.
@sakshampandit1335
@sakshampandit1335 Жыл бұрын
ye ab nhi chalra hai.update soln bnao
@rohitvhanmore8742
@rohitvhanmore8742 Ай бұрын
ethna he hai kya questions string k ma'am abh recursion chalu karo aap 🥲
@Electrocode_gk
@Electrocode_gk 8 ай бұрын
some of the testcases failing
@riteshmishra5008
@riteshmishra5008 Жыл бұрын
for "+ -12" it is showing 0
@sourjadhar9332
@sourjadhar9332 Жыл бұрын
It should show 0
@yogeshyts
@yogeshyts 2 жыл бұрын
easy tha but test case bekar the
@bhuvandahal421
@bhuvandahal421 Жыл бұрын
After multiple tries, I came up with this solution: class Solution { public: int myAtoi(string s) { int flag = 0; long int result = 0; int j = 0; for(int i = 0; i < s.length(); ++i) { if(isdigit(s[i])) { result = result*10 + int(s[i]) - 48; if(flag*result > 2147483647) { return 2147483647; } else if(flag*result < -2147483648) { return -2147483648; } ++j; if(flag == 0) { flag = 1; } } else if(s[i] == '-' || s[i] == '+') { if(!flag && s[i] == '-') { flag = -1; } else if(!flag && s[i] == '+') { flag = 1; } else { break; } } else if(j || flag || flag == -1) { break; } else if(s[i] != ' ') { return 0; } } result *= flag; return (int)result; } };
@omsharma9683
@omsharma9683 10 ай бұрын
Awesome Explanation !!
@AyushiSharmaDSA
@AyushiSharmaDSA 10 ай бұрын
thank you :)
STRING TO INTEGER (ATOI) | PYTHON | LEETCODE # 8
15:04
Cracking FAANG
Рет қаралды 12 М.
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 52 МЛН
Trapped by the Machine, Saved by Kind Strangers! #shorts
00:21
Fabiosa Best Lifehacks
Рет қаралды 41 МЛН
Миллионер | 3 - серия
36:09
Million Show
Рет қаралды 1,8 МЛН
Car Bubble vs Lamborghini
00:33
Stokes Twins
Рет қаралды 45 МЛН
Big-O Notation - For Coding Interviews
20:38
NeetCode
Рет қаралды 513 М.
Object-Oriented Programming is Embarrassing: 4 Short Examples
28:03
Brian Will
Рет қаралды 2,1 МЛН
Implement atoi | Convert string to integer
5:52
Techdose
Рет қаралды 89 М.
DSA Phir se with Sumeet | Leetcode 8 | String to Integer
6:40
Top 7 Algorithms for Coding Interviews Explained SIMPLY
21:22
Codebagel
Рет қаралды 440 М.
Compare Version Numbers | Leetcode 165 | Strings | Day-25
14:29
Ayushi Sharma
Рет қаралды 10 М.
Coding Interview | Software Engineer @ Bloomberg (Part 1)
30:05
Keep On Coding
Рет қаралды 4,7 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 52 МЛН