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. !!!!!
@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: ruclips.net/video/aa2ijyWBBIc/видео.html&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.
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. 👍
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
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.
and you won't get hired, this problem is not a test of your syntax
2 года назад+9
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
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
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.
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(‘’)
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.
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)
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. !!!!!
Congrats, you deserve it!!! 🎉🎉🎉 And thanks for the kind words.
@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: ruclips.net/video/aa2ijyWBBIc/видео.html&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.
congrats!
Hey @rideaff, I am also preparing for FAANG would like to connect and discuss . Please provide your linkedin profile.
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. 👍
This channel is extremely undervalued. It should have at least 500K subscribers.
A big change from yesterdays Hard to todays... reverse a string
😏
They changed it to weekly .I guess this week is two pointers.
Slicing works but Incase interviewer doesn't allow us to use built in functions then swapping is great
No way, I love you because you upload videos everyday.
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"
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
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.
@@CoolerJ0k3r thank you for the advice. I appreciate it. You are right. I will never know until I try
Heyy buddy,which position did you get?
using slice trick print(s[::-1]) should work as well
and you won't get hired, this problem is not a test of your syntax
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
Isn't s.reverse() also works for this problem?
Thank you for your amazing videos
thanks for the videos!
also, what software are you using to draw?
I use Paint3D
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
Java
class Solution {
public void reverseString(char[] ar) {
int i=0;
int j=ar.length-1;
while(i
Would the space compexity of the recursive solution be O(1) for languages that support tail recursion?
Why s=s[::-1] is not working? Could you please tell.
F
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.
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(‘’)
Asymptotically O(n), but much slower.
if possible to use nodeJs then please solve problem on nodeJs
Aren't the first solution is n/2? And why the stack solution is faster then the first one.
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.
No big O notation disregards constants, and runtime is inconsistent, the second solution might not actually be faster on average
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)
What software do you use to record your videos?
I used a while loop, then i start print with the last index the ... Until the index 0
Great going !!!!
Love your stuff
Thanks
are you using your mouse to draw?????
perhaps
@@NeetCode what a boss
thanks for help!!!
What about...
return s[::-1]
???
You need to reverse it in place, the s is still in the same order
Other way:
new_str_list = []
new_str_list[:0] = "".join(str_list)[::-1]
return new_str_list
Please solve Leetcode 321 ..
Oh great!
Just came here to say [::-1]
I was also thinking this.
But in leetcode it didnt work. I dont know why
F
🥺❤️👊🏾
second!
Why is stack faster?
According to me both of them are pretty much similar interns of no.of operations and loops