We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!! Questions you might like: ✅✅✅[ Tree Data Structure ] : th-cam.com/play/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls.html ✅✅✅[ Graphs Data Structure ] : th-cam.com/play/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C.html ✅✅✅[ December Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA.html ✅✅✅[ November Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e.html ✅✅✅[ August Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe.html ✅✅✅July Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC-.html ✅✅✅June Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG.html ✅✅✅May Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e.html ✅✅✅Cracking the Coding Interview - Unique String: th-cam.com/play/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE.html Struggling in a question?? Leave in a comment and we will make a video!!!🙂🙂🙂
Thank you for this explanation! I see there are many ways to try and solve this problem. This way and the animations you used really helped me to properly conceptualize everything and understand your code.
you just managed to give the best explanation of this problem with the most optimal solution and its edge cases, space time complexity within just 5 mins ... brilliant
Super clear. I often shake my head at the solutions in LC, they nearly always are more complicated than they need to be and you just proved that again.
I'm a little confused about what m is. In the instructions, it says that m is the size of nums1. If that were the case, shouldn't m be 6 in our example here?
What I don't understand is why we don't need to write any "append" or "push" or any code that actually changed the value from 0 to the new value. It's just changed? Am I missing something?
In leetcode we just have to write the method(which contains main algorithm), printing and taking input is done by leetcode only...hope it will clear your doubt...(even in questions it is also written "you don't have to print anything"....
But we are not taking extra space to add the elements right? We are just using the already given array to add elements. Whenever there is a new requirement for space, space complexity increases. Here we could have used a 3rd array of size m+n-1 to add the elements which would've increased our space complexity to O(n). But instead we used the given array which made our space comp to O(1)
Because she said we can sort the merged array using arrays.sort. Java uses quicksort internally in Arrays.sort method, which has the time complexity of nlogn.
We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!!
Questions you might like:
✅✅✅[ Tree Data Structure ] : th-cam.com/play/PLJtzaiEpVo2zx-rCqLMmcFEpZw1UpGWls.html
✅✅✅[ Graphs Data Structure ] : th-cam.com/play/PLJtzaiEpVo2xg89cZzZCHqX03a1Vb6w7C.html
✅✅✅[ December Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xo8OdPZxrpybGR8FmzZpCA.html
✅✅✅[ November Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2yMYz5RPH6pfB0wNnwWsK7e.html
✅✅✅[ August Leetcoding Challenge ] : th-cam.com/play/PLJtzaiEpVo2xu4h0gYQzvOMboclK_pZMe.html
✅✅✅July Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wrUwkvexbC-vbUqVIy7qC-.html
✅✅✅June Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2xIfpptnCvUtKrUcod2zAKG.html
✅✅✅May Leetcoding challenges: th-cam.com/play/PLJtzaiEpVo2wRmUCq96zsUwOVD6p66K9e.html
✅✅✅Cracking the Coding Interview - Unique String: th-cam.com/play/PLJtzaiEpVo2xXf4LZb3y_BopOnLC1L4mE.html
Struggling in a question??
Leave in a comment and we will make a video!!!🙂🙂🙂
This is probably the best explaination of this problem on youtube, Thank you for this
Thank you!! 😀
Do share and subscribe if this video helped you!! 🙂
Thank you for this explanation! I see there are many ways to try and solve this problem. This way and the animations you used really helped me to properly conceptualize everything and understand your code.
Really glad you liked it !!! Thanks for your comment !!
you just managed to give the best explanation of this problem with the most optimal solution and its edge cases, space time complexity within just 5 mins ... brilliant
Thank you!!
3 years!!! And this is still the best solution. THANK YOU.
Super clear. I often shake my head at the solutions in LC, they nearly always are more complicated than they need to be and you just proved that again.
Thank you!!
best explanation for this question forever.
Glad you liked it !!
Much simpler code with best explanation!
Glad it was helpful!
Such a beautiful explaination. My all doubts are cleared now.
Thank you!!
Excellent Explanation. Thank you
this is the best explanation of this problem 💯
Thank you!!
This is the best explanation
Thank you!!
Nice and concise explanation with good animations. Thank you! :)
Thank you!!
I liked this video approach, very glad I found this video.
Thank you!!
Best Solution and Explaination of this question
Thank you!!
Such an easy to follow explanation, thank you!
Hi....I have a douth...actually iam a beginner so...my douth is
How this code output gets printed without print
@@bts2287 this is on leetcode platform, we just have to put our condiotns in this the backend process will automatically be executed.
@@shashankvashishtha935 thankyou👍
very well explained with visual thank you so much for this amazing content
Thank you!!
Very good visualization ...great work !
Thanks !!
Great explanation ❤
Glad you liked it
what an explaination ......literally thanks a lot
Thanks
Best!
Thank you!!
Excellent work ka💥
Thank you!!
hi! thank you so much for this elegant solution. i had to repeatedly do it on paper in order to comprehend why this works but the idea is great!
Hey one douth how this code will generate output without print
littlrly great explanation and also ppt presentation
Thanks
thank you 😍 this channel always helpful
Glad to hear that!!!
Greatest approach for this problem
Thank you!!!
Very good explanation ... Thanks a lot .
Thank you!!
I'm a little confused about what m is. In the instructions, it says that m is the size of nums1. If that were the case, shouldn't m be 6 in our example here?
From what I gather is the amount of non-zero numbers in nums1. This problem is confusing
Awesome explanation! loved it!
Thank you!!
It shows me array index out of bound exception what do I do
Excellently explained
Thank you!!
good animation and exprenation mem Thank You :) .
Thank you!!
why> p>=0 and q>=0 ?
2:03 what's i? i =m+n-1.
Thank you very well explained
KEEP WORKING THANK YOU
Thank you
Very well good optimal approach explanation 👏! You are voice so cute💗!Thank you..
Thank you! 😃
When looking at the question how do you perform that kind of a solution in your mind ?
What I don't understand is why we don't need to write any "append" or "push" or any code that actually changed the value from 0 to the new value. It's just changed? Am I missing something?
Since it is an array, we can directly update the value.
Maza aya..
Thank you!!
Thank You !
Thank you!!
hey..thanks
Welcome!
Thanks
Thank you!!
This question may sound stupid since iam a beginner....so my question is
🔸️how this output will generate without print ....?
In leetcode we just have to write the method(which contains main algorithm), printing and taking input is done by leetcode only...hope it will clear your doubt...(even in questions it is also written "you don't have to print anything"....
@@mehulsingh1216 okay👍 , Thank you🤗
thankyou sister
Thank you!!
Nicely done ✔
Thanks !!
Thanks guys
Our pleasure!
Thank u ❣️
Thank you!!
Thanks 👍
Welcome 👍
Beautiful
Thank you!!
Amazing
Thank you!!
Great explanation but how is the space complexity constant time since we are adding elements to back of the array ?
But we are not taking extra space to add the elements right? We are just using the already given array to add elements. Whenever there is a new requirement for space, space complexity increases. Here we could have used a 3rd array of size m+n-1 to add the elements which would've increased our space complexity to O(n). But instead we used the given array which made our space comp to O(1)
class Solution {
public:
void merge(vector& nums1, int m, vector& nums2, int n) {
int p1 = 0;
int p2 = 0;
for(int i = 0; i < m+n; i++)
{
if(n == 0 ) break;
if(m == 0) nums1[0] = nums2[0];
if(i < m)
{
if(nums1[i]
btw your 2 pointer approach is the best, loved that explaination
♥♥♥
can you please explain in C++
time limit exceeded man
HI, how to solve the same question with this kind of parameter ?
public void merge(List< Integer>nums1, int m, List nums2, int n)
list and array both are index based so that will be same as this problem.
Time Limit Exceeded at the time of run.
Why I can not figure out this solution on my own :( So clever!!
Thank you!!
why is p2 >= 0 in the while loop condition instead of p1>=0 in the while loop condition?
Because nums1 always greater then nums2 to thats why we take the validation of nums2 (p2>=0)
because in the question it is given that we need to modify nums1, ie. size of nums1 will always be greater than that of nums2
Why is the time complexity O(KlogK)? Can you please explain 1:02
Because she said we can sort the merged array using arrays.sort. Java uses quicksort internally in Arrays.sort method, which has the time complexity of nlogn.
Error code
getting ArrayIndexOutOfBoundsException error
int p1 = m - 1, p2 = n - 1, i = m + n - 1;
while (p2 >= 0) {
if (p1 >= 0 && nums1[p1] > nums2[p2]) {
nums1[i--] = nums1[p1--];
} else {
nums1[i--] = nums2[p2--];
}
}
System.out.println(Arrays.toString(nums1));
}
Awesome content! Subscriber++;
Thanks!! Do share like and subscribe!!
Hey Siri.😄
thanks
Most welcome!! 🙂 Do check out our latest giveaway video and participate!! 🙂