Excellent content. This is the second video I watch which allows one to be able to devise a nicer solution simply by sorting the array. The hash map solution is genius and is not complicated I will now, always look at a problem and find out how I can solve it by first thinking "Would sorting this array help to simplify the solution"
Good video, very similar to my university lectures. I think the reason a lot of people fail to learn some things on their own is that they just see code and want to understand it magically, you need to get the logic behind stuff.
06:03 - Method 1: Using Sorting This is basically sliding window solution, when you have two pointers , left and right and you move them correspondingly.
I watched two other videos before coming here , to be honest you are the best one . I only understand from you because other people talk too long without explaining they talk about the problem not the solution. You even taught me the math side of this . Thank you , I subscribed. I will watch the rest of the solutions
sir @nikoo28 ,there is a mistake in two pointer approch i think where if => num1 and num2 are the same (e.g., nums = [3,3], target = 6), so code will return the same index for both numbers, especially if there are duplicates in the original array. for ex nums = [3,3] target = 6 Output [1,1] Expected [0,1] which is wrong so should we apply something else here?
I had a similar issue with this test case as well. The way I fixed it is I made sure I was only inserting a {key:value} pair into my hashMap (example: target - nums[index]) at the end of the for-loop. I evaluate if condition ( map.containsKey(target - nums[index]) ) first, if not satisfied then I insert this new {key:value} pair into my hashMap and continue on with the next iteration of the for-loop. This generalizes the solution to fix the [3,3] target = 6 case. Also I haven't tested Nikhil's solution but it looks correct to me.
@@coldcases_2 There isn't a mistake in the two pointer approach. You need to add complexity for the case when i = j, that takes care of this special case.
@@coldcases_2 when doing the brute force method you can fix this condition by for () { for() { if (target == nums[I] + nums[J]) && I != J then return (I,J); } } This takes care of all test cases. We added some complexity in the if condition.
For a very big input size, yes there will be collisions…but for the domain of this problem you should be just fine. Good to discuss this with your interviewer though 😄
Hello I have a small doubt ? How we return two index values here map.get(complement),i); Can any one explain 🤔 does it return complement index and current I value ?
what is this """'' return new int[]{map.get(complement),i}; """" ? as it throws error and i am getting you've used curly brackets with new int[]...................please reply..........................
Sir will 3rd Method will work if array has Duplicate elements . Becoz in HashMap , the key cannot be duplicate. And if array elements repeats , they duplicate key is found. PLZZZZ PLZZ EXPLIAN THIS SIR
since the problem says you will have EXACTLY ONE SOLUTION, you do not need to worry about duplicate number. Because if a duplicate number exists, then you will have 2 possible solutions...and hence that is not a valid scenario.
Problem 1: Description: Given a number 𝑛 n, write a function to find the largest number that has the same set of digits as 𝑛 n but is smaller than 𝑛 n. If no such number exists, return an appropriate message. Example: Input: 𝑛 = 531476 n=531476 Output: 531467 531467
At 12:58, I am supposed to add "8" to the hash table and not "11".
Sorry for the error.
😅😅😅😅😅😅😅 15:52 😅😅😊😅😅😅 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 15:52 😅 15:52 15:52 15:52 15:52 15:52 15:52 15:52
This is absolutely the best explanation on TH-cam. Everyone else goes straight to coding and doesn't break down the logic beforehand.
Happy that I could help :)
So nice of you to put this in a simple yet insightful manner, thanks a lot.
Excellent content. This is the second video I watch which allows one to be able to devise a nicer solution simply by sorting the array. The hash map solution is genius and is not complicated
I will now, always look at a problem and find out how I can solve it by first thinking "Would sorting this array help to simplify the solution"
Awesome, thank you!
@@nikoo28 you are welcomed
Underrated channel.
Good video, very similar to my university lectures.
I think the reason a lot of people fail to learn some things on their own is that they just see code and want to understand it magically, you need to get the logic behind stuff.
Sir😄, I have no words, I have never seen anyone explain this nicley, thank you so much❤
Thank you so much for your kind words.
thank you soooo much! I checked out so many videos about this question. finally your video helped me out! firmly subscribed to your channel
you r really an excellent teacher one thing i want to tell ur explanation is better that striver thanks for providing such videos
06:03 - Method 1: Using Sorting
This is basically sliding window solution, when you have two pointers , left and right and you move them correspondingly.
I watched two other videos before coming here , to be honest you are the best one . I only understand from you because other people talk too long without explaining they talk about the problem not the solution. You even taught me the math side of this . Thank you , I subscribed. I will watch the rest of the solutions
I prefer to focus on the problem. Language is a tool anyway, and they will keep changing and evolving. Thanks for the sub!!
Such a great way of explaining this problem. You have redefined teaching sir!!! Amazing Work!!!!
Thanks a ton
One of the best way of teaching . Sir Keep posting more videos of dsa. 👍👍
Thank you so much for your support :)
Love the way you teach, TYSM☺
Only just got into coding a few days ago coming from a teacher background. Great explanations!
Best Video Explanation so far !!!
I was searching for the solution but do not found dryryn but u did it thank bro ❤️
Thank you for taking the time to create this video and make a clear explanation
Please keep uploading DSA/leetcode videos, they all are really helpful, thanks!
More to come!
you are the best.I really appreciate your hard work and step-by-step approach to how to overcome with a solution. Hats off
thanks for the appreciation and motivation :)
Thanks a lot, I was able to understand this problem thanks to your efforts.
You're by far the most detailed explainer I've seen. I've seen a few, but you're really amazing. Having a coding interview soon.
All the very best for your upcoming interviews :)
your explanation is for more better than other youtuber
Glad you feel that way :D
Best way to teach sir plz discuss more question and make a proper playlist ❤❤❤
Check out my playlists in the channel :)
You explained it very well, best video out there regarding this solution!!"!!!!
Thank you for the video it really helped me!
Thank you very much, finally understood
Best explanation 👌
such clear explantion , subscribed
Thank you, you are the best! Visualizing the code helped me a lot
You're welcome!
awesome explanation..keep teaching us
Thank you bro you do grate things
your explanation is very simple and easy to understand
Iam so happy to see this video
so happy to read this
sir @nikoo28 ,there is a mistake in two pointer approch i think where if => num1 and num2 are the same (e.g., nums = [3,3], target = 6), so code will return the same index for both numbers, especially if there are duplicates in the original array. for ex nums =
[3,3]
target =
6
Output
[1,1]
Expected
[0,1] which is wrong so should we apply something else here?
I had a similar issue with this test case as well.
The way I fixed it is I made sure I was only inserting a {key:value} pair into my hashMap (example: target - nums[index]) at the end of the for-loop. I evaluate if condition ( map.containsKey(target - nums[index]) ) first, if not satisfied then I insert this new {key:value} pair into my hashMap and continue on with the next iteration of the for-loop. This generalizes the solution to fix the [3,3] target = 6 case.
Also I haven't tested Nikhil's solution but it looks correct to me.
@@matthewzarate8851 i was talking about two pointer approch there is mistake in two pointer approch i already give example in my comment
@@coldcases_2 There isn't a mistake in the two pointer approach. You need to add complexity for the case when i = j, that takes care of this special case.
@@coldcases_2 when doing the brute force method you can fix this condition by
for () {
for() {
if (target == nums[I] + nums[J]) && I != J then return (I,J);
}
}
This takes care of all test cases. We added some complexity in the if condition.
Kudos! Great explanation brother.P.s: Bro, you sound exactly like Pennywise from It.
Thank you ❤
Good one
Very smooth sir
Great video best explanation
awesome video... keep making them
For the second solution where we are using hashmap, the time complexity of finding an element is also O(n) in case of hash collisions
For a very big input size, yes there will be collisions…but for the domain of this problem you should be just fine.
Good to discuss this with your interviewer though 😄
awesome tutorial sir
Amazing
I do not know why he gets very few likes and he is the best teacher for explaining the leetcode problems
so happy you believe in me. Please share the videos if possible. Trying my best with SEO to get ranked up in search results.
Brother don't stop making leetcode questions@@nikoo28
we can do this question using two pointer???
but how do you return 2 elements.
Is this possible using binary search?
Hi Nikhil, what program do you use to draw the solution?
GoodNotes 6
thank you for a great explanation, what would be its space complexity?
Which solution do you want the space complexity for? :)
I had a question about the tastable, 19-4 is 15, but it is on the table so why don't we stop there? Thank you
I caan easily understand this code
Best
Hello I have a small doubt ? How we return two index values here map.get(complement),i);
Can any one explain 🤔 does it return complement index and current I value ?
AT 10:31 the method is not working for negative numbers in the array;
the optimized method takes care of all different test cases
@@nikoo28 Ohk Thanks Sir
Why new is written in return
Awesome channel! Why I Find it so late?
Glad I could help you 😄
sir
what language you are used here
Java
Can anybody tell how to write the main function code for the same function.
Just create an object of the class and call it in the main method
@@nikoo28 thanks.
what is this """'' return new int[]{map.get(complement),i}; """" ? as it throws error and i am getting you've used curly brackets with new int[]...................please reply..........................
It gets the complement pair and then returns it as an array.
Sir will 3rd Method will work if array has Duplicate elements . Becoz in HashMap , the key cannot be duplicate. And if array elements repeats , they duplicate key is found. PLZZZZ PLZZ EXPLIAN THIS SIR
since the problem says you will have EXACTLY ONE SOLUTION, you do not need to worry about duplicate number. Because if a duplicate number exists, then you will have 2 possible solutions...and hence that is not a valid scenario.
@@nikoo28 but in the example there is repetitive element
@@nikoo28 we have a valid scenario [3,3], and this method won't work :(
subbed!
its cool
Dont stop DSA questions
bro plz do in python
🎉
koko eating banana 875 leetcode question
It is available now: th-cam.com/video/JGYXNpZaW2U/w-d-xo.htmlsi=2ftslOTD1LCE8-r2
100
😢
Problem 1:
Description:
Given a number
𝑛
n, write a function to find the largest number that has the same set of digits as
𝑛
n but is smaller than
𝑛
n. If no such number exists, return an appropriate message.
Example:
Input:
𝑛
=
531476
n=531476
Output:
531467
531467