No video

Reverse String - 3 Ways - Leetcode 344 - Python

  Рет қаралды 54,889

NeetCode

NeetCode

Күн бұрын

Пікірлер: 62
@rideraff
@rideraff 2 жыл бұрын
Hey @NeetCode thanks A TON!! I couldn't have cracked FAANG interviews without your help. I interviewed with 3 FAANG companies and got offer letters from 2. This is the biggest milestone of my life and yes a dream come true. So thank you very much for all the great work you're doing :) You THE G.O.A.T. !!!!!
@NeetCode
@NeetCode 2 жыл бұрын
Congrats, you deserve it!!! 🎉🎉🎉 And thanks for the kind words.
@rideraff
@rideraff 2 жыл бұрын
@Aman Daredi Hi, I split my preparations into 3 parts. 1. Coding, 2. Behavioral, 3. System Design. Let me explain in fewer words as possible, 1. Coding: I solved around 130 leetcode questions -> Blind 75 + Top questions from leetcode (I skipped some ofc :D ). Despite doing that I still got questions in the interview that were not available on leetcode or any other forums. I didn't completely bum out on those, I was able to implement 75% - 90% of the problem in the interviews. So, It's not about how many problems you solve, It's about understanding the common patterns and implementing them. Neetcode explains it so well in this video: kzbin.info/www/bejne/l5KVmp2vjKd1f8U&ab_channel=NeetCode . Note: In the interviews, make sure you talk through your logic before coding. Mention the time and space complexities even before they ask. Also, explain how you measured time and space complexities for your logic. Quick Tip: Before jumping into leetcode, get better at basics. Data Structures, Common search and sort Algorithms, common Traversals, complexities, etc. Spend some time on this. Sometimes the interview problems may be so easy to implement but your lack of knowledge in the basics would fail you under the pressure (Trust me you do not want be in such situations) For example, instead of memorizing that Dictionary lookup is O(1), you should know what "lookup" is and how it works for a dictionary. Then you'll be able to calculate the complexity for any given data structure or algorithm easily. 2. Behavioral: Amazon leadership principles cover most of the behavioral questions asked in any interview. I have a list of questions here - github.com/chickenwingstossed/behavioralquestions . This list has amazon questions and additional questions which I have gathered from my experience. 3. System Design: This really comes down to the title, the company, and the job description of the position you have applied for. The recruiter may or may not give you details about the team but you can still ask them. Just make sure you learn the common System Design questions and Design Patterns. I hope the above helps. Best of luck to everyone. Never. Give. Up. Keep grinding \m/ Thank you @NeetCode for giving me this opportunity to share my experience.
@leeroymlg4692
@leeroymlg4692 Жыл бұрын
congrats!
@maheshtiwari-yo8ux
@maheshtiwari-yo8ux 10 ай бұрын
Hey @rideaff, I am also preparing for FAANG would like to connect and discuss . Please provide your linkedin profile.
@uditsharma5688
@uditsharma5688 2 жыл бұрын
Direct swap and stack solutions were intuitive for me but didn't notice that we could also use recursion. Thankyou for showing multiple solution instead of giving just the most efficient one. 👍
@gianniprocida3332
@gianniprocida3332 2 жыл бұрын
This channel is extremely undervalued. It should have at least 500K subscribers.
@floydian25
@floydian25 Жыл бұрын
Incase someone is looking for a solution for a string: def reverse(s): if len(s) == 0: return s return (reverse(s[1:]) + s[0]) Here is how it works: Input: "hello" reverse("hello") reverse("ello") + "h" reverse("llo") + "e" reverse("lo") + "l" reverse("o") + "l" reverse("") + "o" => "" + "o" => "o" + "l" => "ol" + "l" => "oll" + "e" => "olle" + "h" => "olleh"
@NeetCode
@NeetCode 2 жыл бұрын
A big change from yesterdays Hard to todays... reverse a string
@__________________________6910
@__________________________6910 2 жыл бұрын
😏
@clashgamers4072
@clashgamers4072 2 жыл бұрын
They changed it to weekly .I guess this week is two pointers.
@Cloud-577
@Cloud-577 2 жыл бұрын
Please I need an advice. I have been doing leetcode questions for over 3 months now (this is my first time. I’m new to this). I have definitely improved but I don’t think I’m ready for technical interviews yet. How do I improve quickly? I really need to find a job asp for my own mental health wellbeing
@CoolerJ0k3r
@CoolerJ0k3r 2 жыл бұрын
If you aren't already then you'll want to apply to any position you believe you are somewhat qualified for. The best practice you can get is actual technical interviews. You just need to be prepared to receive rejection emails or no response at all. Apply to the jobs you actually want once you feel a bit more comfortable with the technical interviews.
@Cloud-577
@Cloud-577 2 жыл бұрын
@@CoolerJ0k3r thank you for the advice. I appreciate it. You are right. I will never know until I try
@marcus2224
@marcus2224 5 ай бұрын
Heyy buddy,which position did you get?
@triggeredcomments4009
@triggeredcomments4009 2 жыл бұрын
Why is stack faster? According to me both of them are pretty much similar interns of no.of operations and loops
@shakhaoathossain5032
@shakhaoathossain5032 Жыл бұрын
Slicing works but Incase interviewer doesn't allow us to use built in functions then swapping is great
@__________________________6910
@__________________________6910 2 жыл бұрын
No way, I love you because you upload videos everyday.
@NotKevinNguyen
@NotKevinNguyen 2 жыл бұрын
Isn't s.reverse() also works for this problem?
2 жыл бұрын
I think the biggest reason the input is a "char[]" instead of "string" because in most languages strings are immutable. That means, you can't change them once you create it. Even if you think you change them, you actually create a new string object which automatically means that you need an extra memory. en.wikipedia.org/wiki/Immutable_object
@ahmadtarawneah
@ahmadtarawneah 2 жыл бұрын
Thank you for your amazing videos
@kritikabhateja110
@kritikabhateja110 2 жыл бұрын
Why s=s[::-1] is not working? Could you please tell.
@issamuhsen1245
@issamuhsen1245 Жыл бұрын
F
@nikhil_a01
@nikhil_a01 Жыл бұрын
The problem requires you to modify s in place. What s=s[::-1] does is create a new reversed list and then assign it to s. If you do s[:] = s[::-1] it will actually copy each element of the reversed list into s. More in-depth explanation: Imagine you have a list and a variable arr which points to it. arr -> [1, 2, 3, 4] When you call reverseString(arr), inside the function the variable s is ANOTHER pointer to the input list. arr -> [1, 2, 3, 4] [1, 2, 3, 4] s -> [4, 3, 2, 1] But when you return from the function, s goes away since it's a local variable. LeetCode checks the value of arr and sees that you haven't reversed it.
@harveylesterarcilla9329
@harveylesterarcilla9329 2 жыл бұрын
using slice trick print(s[::-1]) should work as well
@juansymontano
@juansymontano 6 ай бұрын
and you won't get hired, this problem is not a test of your syntax
@christinaphan5124
@christinaphan5124 2 жыл бұрын
thanks for the videos! also, what software are you using to draw?
@NeetCode
@NeetCode 2 жыл бұрын
I use Paint3D
@fieryfeather
@fieryfeather 2 жыл бұрын
Would the space compexity of the recursive solution be O(1) for languages that support tail recursion?
@vdyb745
@vdyb745 2 жыл бұрын
Great going !!!!
@pauljones9150
@pauljones9150 2 жыл бұрын
Love your stuff
@lymphtics9218
@lymphtics9218 2 жыл бұрын
Could someone explain what would be the space and time complexity of reversing a string in JS using built in methods like str.split(‘’).reverse().join(‘’)
@omkarbhale442
@omkarbhale442 Жыл бұрын
Asymptotically O(n), but much slower.
@anatoliy-gr
@anatoliy-gr Жыл бұрын
thanks for help!!!
@saraex8558
@saraex8558 2 жыл бұрын
Thanks
@dandendrasingh7326
@dandendrasingh7326 2 жыл бұрын
Aren't the first solution is n/2? And why the stack solution is faster then the first one.
@CoolerJ0k3r
@CoolerJ0k3r 2 жыл бұрын
Big O notation doesn't care about the insignificant values. The only thing that matters is the part of the notation that is most significant. For example if you had an algorithm that took 3n^2 + 6n + 1 to run then the big O would be O(n^2) because n^2 is the most significant part. It would also not be n/2 because you access each element within the array once and there are n elements. Sorry if I didn't explain it very well.
@derekyoungman3895
@derekyoungman3895 2 жыл бұрын
No big O notation disregards constants, and runtime is inconsistent, the second solution might not actually be faster on average
@derekyoungman3895
@derekyoungman3895 2 жыл бұрын
The definition of big O notation is as follows: Consider 2 functions f(n) and g(n) f(n) is in O(g(n)) if there exists constants a and c such that for all n >= a, f(n)
@algorithmo134
@algorithmo134 2 жыл бұрын
What software do you use to record your videos?
@domeshsinha7670
@domeshsinha7670 2 жыл бұрын
if possible to use nodeJs then please solve problem on nodeJs
@_sam_ael
@_sam_ael 9 ай бұрын
I used a while loop, then i start print with the last index the ... Until the index 0
@weishin
@weishin 2 жыл бұрын
are you using your mouse to draw?????
@NeetCode
@NeetCode 2 жыл бұрын
perhaps
@weishin
@weishin 2 жыл бұрын
@@NeetCode what a boss
@numberonep5404
@numberonep5404 2 жыл бұрын
Two other solutions, first another even less efficient stack solution: class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ stack1,stack2 = [], [] while s: stack1.append(s.pop()) while stack1: stack2.append(stack1.pop()) while stack2: s.append(stack2.pop()) then another iterative solution : class Solution: def reverseString(self, s: List[str]) -> None: """ Do not return anything, modify s in-place instead. """ n = len(s) for i in range(n//2): s[i], s[n-i-1] = s[n-i-1], s[i] Making it 5 more or less efficient ways to do the same thing xD coding is fun
@tanoybhowmick8715
@tanoybhowmick8715 Жыл бұрын
Oh great!
@rajatagrawal7016
@rajatagrawal7016 2 жыл бұрын
Java class Solution { public void reverseString(char[] ar) { int i=0; int j=ar.length-1; while(i
@JimmyBrock
@JimmyBrock Жыл бұрын
What about... return s[::-1] ???
@juansymontano
@juansymontano 6 ай бұрын
You need to reverse it in place, the s is still in the same order
@vineethnc8934
@vineethnc8934 2 жыл бұрын
Please solve Leetcode 321 ..
@gonzalochacaltana2735
@gonzalochacaltana2735 Жыл бұрын
Other way: new_str_list = [] new_str_list[:0] = "".join(str_list)[::-1] return new_str_list
@ericlefort
@ericlefort 2 жыл бұрын
Just came here to say [::-1]
@kritikabhateja110
@kritikabhateja110 2 жыл бұрын
I was also thinking this. But in leetcode it didnt work. I dont know why
@issamuhsen1245
@issamuhsen1245 Жыл бұрын
F
@kalahari8295
@kalahari8295 2 жыл бұрын
🥺❤️👊🏾
@pira9850
@pira9850 2 жыл бұрын
second!
Valid Palindrome II - Leetcode 680 - Python
7:46
NeetCode
Рет қаралды 44 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 486 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН
Oh No! My Doll Fell In The Dirt🤧💩
00:17
ToolTastic
Рет қаралды 13 МЛН
What will he say ? 😱 #smarthome #cleaning #homecleaning #gadgets
01:00
Magic or …? 😱 reveal video on profile 🫢
00:14
Andrey Grechka
Рет қаралды 54 МЛН
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 302 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 216 М.
Shortest Bridge - Leetcode 934 - Python
14:51
NeetCode
Рет қаралды 37 М.
My Brain after 569 Leetcode Problems
7:50
NeetCode
Рет қаралды 2,5 МЛН
Reverse Words in a String III - Leetcode 557 - Python
10:18
NeetCodeIO
Рет қаралды 16 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 345 М.
Learn RECURSION in 5 minutes! 😵
5:59
Bro Code
Рет қаралды 148 М.
I gave 127 interviews. Top 5 Algorithms they asked me.
8:36
Sahil & Sarra
Рет қаралды 647 М.
Gli occhiali da sole non mi hanno coperto! 😎
00:13
Senza Limiti
Рет қаралды 24 МЛН