Rotate Array by K places | Union, Intersection of Sorted Arrays | Move Zeros to End | Arrays Part-2

  Рет қаралды 912,171

take U forward

take U forward

Күн бұрын

Пікірлер: 993
@takeUforward
@takeUforward Жыл бұрын
Let's march ahead, and create an unmatchable DSA course! ❤ Timestamps someone please :) Use the problem links in the description.
@brajeshmohanty2558
@brajeshmohanty2558 Жыл бұрын
At 23:47 my mind just got blown away. Me be like: - itna easy kese Benstocks 😂🙏. Bhai iPad ka notes ka bhi pdf dalo na . Tumaaher writing sei sab samajh mai ata hai. Boh tuf sight par itna bada article dekhne sei dar lagta hai 🙂. But you are doing amazing job bhai thank you 🙏😌.
@Atharva_kathiyawadi
@Atharva_kathiyawadi Жыл бұрын
appreciable !!
@ParasSharma-mf8or
@ParasSharma-mf8or Жыл бұрын
Please upload the next video.
@gautamsethiya1397
@gautamsethiya1397 Жыл бұрын
@takeUforward class Solution { public: void rotate(vector& nums, int k) { int n = nums.size(); k =k%n; int temp[k]; for (int i = n - k; i < n; i++) { temp[i - n + k] = nums[i]; } for(int i=n-k-1;i>=0;i--) { nums[i+k]=nums[i]; } for(int i=0;i
@yaswanthmitta8983
@yaswanthmitta8983 Жыл бұрын
for moving zeroes to the end we cen write it in 1 loop instead of two though time complexity is same , complexity for understanding decreases : v oid moveZeroes(vector& nums) { int j=0; for(int i=0;i
@zenithria_414
@zenithria_414 4 ай бұрын
Who is grinding their head with DSA in their summer vacation?? Heartly thanks to striver for making us understand dsa in such depth :)
@prasannagodiyal6736
@prasannagodiyal6736 4 ай бұрын
Me😃
@avgguy7129
@avgguy7129 4 ай бұрын
me too lol
@JohnCena-uf8sz
@JohnCena-uf8sz 4 ай бұрын
bro this course from his website is completely free for now right ? ... or it has premium paid version as well ?
@victory7361
@victory7361 3 ай бұрын
What do u mean by summer vacation 😢?
@AdityaKumar-gx2ip
@AdityaKumar-gx2ip Жыл бұрын
For Right Rotation of Array void rotate(vector arr, int d) { if(d>size) d = d % size; reverse(arr.begin(),arr.end()); reverse(arr.begin()+d,arr.end()); reverse(arr.begin(),arr.begin()+d); }
@bishalkundu7592
@bishalkundu7592 Жыл бұрын
Thanks a lot sir for taking out time from your busy schedule and making videos and uploading those videos in the span of 2-3 days. It takes a lot ot effort. Thanks a lot 😊😊
@arnab_16
@arnab_16 11 ай бұрын
not only your dsa knowledge is good also your communication skill, voice tone , body movement is superb 🥰🥰
@sanjana6931
@sanjana6931 18 күн бұрын
Agreed. He's so smart and confident, definitely a role model to students!
@luckshaeey
@luckshaeey Жыл бұрын
27:00 rotating an array left by 1 place is equal to rotating it right by n-1 places. We can use this information for rotating an array to right by d places.
@takeUforward
@takeUforward Жыл бұрын
Perfect thought!
@bhargavanand7325
@bhargavanand7325 Жыл бұрын
great
@himanshukaushik9223
@himanshukaushik9223 Жыл бұрын
Bhai leetcode pa left rotation question reverse .end() and begin() use karna pad Raha hai but gfg ma nahi why
@bhargavanand7325
@bhargavanand7325 Жыл бұрын
@@himanshukaushik9223 in case of vector we use stl function like begin() and end() but in case of array we don't use it for example in gfg
@himanshukaushik9223
@himanshukaushik9223 Жыл бұрын
@@bhargavanand7325 thanks bro
@ruhiawasthi9
@ruhiawasthi9 4 ай бұрын
I have written this approach for rotating the array to the right by k steps : void rotate(vector& nums, int k) { k%=nums.size(); reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin() + k); reverse(nums.begin()+k, nums.end()); }
@himadriroy7980
@himadriroy7980 Жыл бұрын
I did not only enjoy the lecture but loved it too. Thanks Striver Bhaiya for explaining so lucidly. ❤
@hey-cg3fv
@hey-cg3fv Жыл бұрын
Move zeroes question another approach with O(1) space int j=0; // Firstly taking all non- zeroes number for(int i=0;i O(1)
@ByteBuilder-b6u
@ByteBuilder-b6u 3 ай бұрын
Really your thought process is really clear and the way you write the code is awesome.For union of two arrays you have written the code in such a simpler way whereas in first go I wrote the code this way : vector < int > sortedArray(vector < int > a, vector < int > b) { // Write your code here int i = 0; int j = 0; vector ans; while(i < a.size() && j < b.size()){ if(a[i] < b[j]){ if(i == 0){ ans.push_back(a[i]); } else if(a[i] != a[i-1]){ ans.push_back(a[i]); } i++; } else if(a[i] == b[j]){ if(i == 0){ ans.push_back(a[i]); } else if(a[i] != a[i-1]){ ans.push_back(a[i]); } i++; j++; } else{ if(j == 0){ ans.push_back(b[j]); } else if(b[j] != b[j-1]){ ans.push_back(b[j]); } j++; } } while(i < a.size()){ if(ans.back() != a[i]){ ans.push_back(a[i]); } i++; } while(j < b.size()){ if(ans.back() != b[j]){ ans.push_back(b[j]); } j++; } return ans; }
@honblegaurav9917
@honblegaurav9917 2 ай бұрын
can you tell me why i++ and j++ should be outside of if else loop. because for me it is not accepting the solution but accepts when i put i++ and j++ inside the if else loop
@Str13011
@Str13011 Жыл бұрын
Thank you for all the tutorials, Please keep supporting from starting to get good placement by the help of your tutorials!
@puneetnj
@puneetnj Жыл бұрын
Right Shift Solution(Leetcode 189): k = k % arr.length; reverse(arr, 0, arr.length-1-k); reverse(arr, arr.length-1-k+1, arr.length-1); reverse(arr, 0, arr.length-1);
@hari7939
@hari7939 Жыл бұрын
Just do k=k%n, k=n-k!! as simple as that
@senseiAree
@senseiAree Жыл бұрын
I always thought that the optimal solution to this code was the hashset one that you did in the middle part. It blew my mind when I saw the optimal one... And that too so easy man... Wow .. just wow to your observation ❤
@codeby_chance6728
@codeby_chance6728 5 ай бұрын
Striver please bring string series. Much needed
@sahadevbhaganagare4761
@sahadevbhaganagare4761 Жыл бұрын
me first getting the optimal solution and then finding the brute 🤣🤣
@he_KARTIK
@he_KARTIK 10 ай бұрын
mee too😂
@Vikas-dm9uc
@Vikas-dm9uc 10 ай бұрын
#me2 moment
@helloworld-n1z
@helloworld-n1z 9 ай бұрын
how to remember logic ,i always forget nd cant able to code
@sahadevbhaganagare4761
@sahadevbhaganagare4761 9 ай бұрын
@@helloworld-n1z I am not the right person but still always go back to the code after a week or so and try solving it again. Then review it after a month. That is it, it will get hard coded in your brain after that.
@Me_Meraj
@Me_Meraj 8 ай бұрын
Bro me too 😢 Isi wajah se easy problem solve krne me v time lgta h 😂😂 dimag me bs chlta h ki optimal hi krna h
@AbhishekSingh-rp6hp
@AbhishekSingh-rp6hp Жыл бұрын
Your course is awesome wish I could have found your course a year before currently I am in 3rd year of my clg 😊
@anshu59kumari
@anshu59kumari Жыл бұрын
From which college u r
@AbhishekSingh-rp6hp
@AbhishekSingh-rp6hp Жыл бұрын
@@anshu59kumari Techno International New Town West Bengal
@sanjaykrishna689
@sanjaykrishna689 7 ай бұрын
left rotation to right rotation: simple approach is to think oppositely to left rotation. Shift all elements right of d and add to temp and push it. Just reverse the order of the reverse statements used in left rotation!.
@MotivexBeastt
@MotivexBeastt 9 ай бұрын
Striver is the lion of this community
@MONESHSG
@MONESHSG 6 ай бұрын
Brother, Actually only because of you i came to know what is coding and how to perform our own logic while writing code. Your teaching was nice and I really love it. once before viewing your videos i may code but i don't know how it works internally, but after seeing ur videos it is very easy to understand the working ❣. my first own logic: vector temp; int first = arr[0]; for(int i=1; i
@kushagramishra5638
@kushagramishra5638 Жыл бұрын
Understood 😄. Logic used for right rotate the array k places is that instead of rotating array right by k places I have rotated it n-k places to left . so code for this is - class Solution { public: void rotate(vector& nums, int k) { int n = nums.size(); k = k % n; reverse(nums.begin(),nums.begin()+(n-k)); reverse(nums.begin()+(n-k),nums.end()); reverse(nums.begin(),nums.end()); } };
@Miracle_shaw
@Miracle_shaw Жыл бұрын
hey, me also applied same approach
@itzmartin20
@itzmartin20 Жыл бұрын
same here
@jatinukey4062
@jatinukey4062 Жыл бұрын
Exactly right
@expl0itr
@expl0itr 7 ай бұрын
reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin() + k); reverse(nums.begin() + k, nums.end()); u can do this also.
@tushartyagi4965
@tushartyagi4965 Жыл бұрын
Rotate right ---->>>> void rotate(vector& nums, int k) { vector temp(nums.size()); for(int i=0; i< nums.size(); i++) { temp[(i+k)%nums.size()] = nums[i]; } nums=temp; }
@AniketKumar-tc8cz
@AniketKumar-tc8cz Жыл бұрын
Timestamps: 0:00:00 - Intro 0:00:55 - Q1. Left rotate an array by 1 place 0:07:33 - Q2. Left rotate an array by D places 0:26:36 - Follow up Right rotate an array by D places 0:27:11 - Q3. Moving Zeroes to end 0:40:54 - Q4. Linear Search 0:43:01 - Q5. Union of Two Sorted Arrays 0:59:04 - Q6. Intersection of Two Sorted Arrays 1:12:22 - Outro
@MAX_RITIK
@MAX_RITIK 2 ай бұрын
at 39:57 int j=0; for (int i = 0; i < n; i++) { if(arr[i]!=0){ swap(arr[i],arr[j]); j++; } for moving zeros to end also o(n)
@md.ualiurrahmanrahat2400
@md.ualiurrahmanrahat2400 Жыл бұрын
Thanks for providng such amazing course for completely free. We are intended to you.
@shreyasr2885
@shreyasr2885 2 ай бұрын
he never skips anything, Patience is next level!!
@UECSoumyaRay
@UECSoumyaRay Жыл бұрын
code for right-rotation: void rotate(vector& nums, int k) { int n = nums.size(); if (k > n) { k = k % n; } reverse(nums.begin(), nums.begin()+n-k); reverse(nums.begin()+(n-k),nums.begin()+n ); reverse(nums.begin(), nums.begin()+n); }
@crazybro4383
@crazybro4383 8 ай бұрын
Hii brother can you pls explain me why time complexity of intersection is O(1) and not O(n), where n is the size of larger sized array. Time stamp- 1:12:01
@architha4305
@architha4305 5 ай бұрын
for the first time i guessed which concept can be used it might sound like a small thing but as a beginner who is just learning to code actually implementing codes without any reference and knowing which loop is used is really HUGE for me. THANK YOU SOO MUCH
@zenmonk29
@zenmonk29 4 ай бұрын
same for me. feels like a big leap
@KrishnaKumar-b4m9p
@KrishnaKumar-b4m9p 2 ай бұрын
hi in which question u implemented the code yourself? i am having a hard time in writing code for right rotate an arrray ky k places on my own...
@satishmaurya7032
@satishmaurya7032 Жыл бұрын
What a wonderful video, it was vey good. Your way of teaching concepts through questions is best.
@devanshimehta780
@devanshimehta780 Ай бұрын
my motivation are your efforts, wont let them go in vain, thankyou STRIVER
@aswinsrikanth408
@aswinsrikanth408 Жыл бұрын
Understood and what an explanation Love your explanation bro, just continue doing what you are doing for the coding community Amazing person
@curs3m4rk
@curs3m4rk 8 ай бұрын
I recommend everyone to solve the linked leetcode problems attached as well, as the code needs to be tweaked little bit . So u can understand and do by yourself Great approaches Striver. thanks
@valiant4498
@valiant4498 10 ай бұрын
Guys i just wanna ask something....r u guys doing all these problems on your own or like just watching the lectures
@ishanmoykhede9484
@ishanmoykhede9484 10 ай бұрын
First Understanding the problem then finding approach to solve it then if I make the correct solution then codding it in vs code and moving to nxt question and if I didn't get the solution then watching striver
@AbhinavTiwari-u7b
@AbhinavTiwari-u7b 5 ай бұрын
done the assignment and understood each and every concept . Sir appreciate your hardwork
@sikanddhingra5835
@sikanddhingra5835 10 ай бұрын
bhai ki pehli video lgayi h ye mene. bohut maja aya, dil garden garden hogya bilkul. thanku bhai.😁
@vasudev6559
@vasudev6559 Ай бұрын
One more approach can be: void moveZeroes(vector& nums) { int n=0; for(int i=0;iO(N) SC->O(1) similar but less code
@kirankawade3424
@kirankawade3424 Жыл бұрын
Thank you so much for sharing the content free of cost!! very nicely explained too😘
@RahulKumar-bd6py
@RahulKumar-bd6py Жыл бұрын
Your are best amongst all I found on internet hatsoff to you sir.
@yashsaxena7787
@yashsaxena7787 9 ай бұрын
Great! btw in the worst case of Intersection, the space complexity would be O(n1>n2?n2:n1) because whichever one is smaller matches completely with the other array and ends. P.S.- the space is for returning the answer and not solution.
@b.bhargavitejaswi7655
@b.bhargavitejaswi7655 12 күн бұрын
best teacher i have ever found in internet
@uttamvashisth4072
@uttamvashisth4072 Жыл бұрын
Salute to this consistency.
@rohandhalpe9084
@rohandhalpe9084 Жыл бұрын
😆😆
@saurabhtiwari9614
@saurabhtiwari9614 Жыл бұрын
@@rohandhalpe9084 😡😡😡
@rohandhalpe9084
@rohandhalpe9084 Жыл бұрын
@@saurabhtiwari9614 kya hua bhai 😔
@saurabhtiwari9614
@saurabhtiwari9614 Жыл бұрын
@@rohandhalpe9084 Bhai aaisa face kyo bnaya h.
@PonVignesh-gv1xp
@PonVignesh-gv1xp 5 ай бұрын
Learning a lot outta this guy..
@chiragbirla5606
@chiragbirla5606 Жыл бұрын
One thing striver..... In the sheet for the same question as we know there is a link attached for the gfg version and for the leetcode version but in some cases leetcode version is harder and sometimes gfg version. So please pick the hard problem for that
@ammarshaikh4054
@ammarshaikh4054 4 ай бұрын
if you are geting confused in last loop at 18:55 i.e for(int i=n-d; i
@siddiqabr7110
@siddiqabr7110 2 ай бұрын
Bro the answer is fkn wrong has no one noticed it at all
@ammarshaikh4054
@ammarshaikh4054 2 ай бұрын
​@@siddiqabr7110Yes bro, i also got it wrong, when referred from video!
@AdityaKumar-be7hx
@AdityaKumar-be7hx Жыл бұрын
Actually, there is another optimal solution for moving zeroes problem. It is similar to the function we use in quicksort algorithm (quickselect part for arranging elements around pivot). void Optimal2(̀vector& nums) { int j=-1, n=nums.size(); for(int i=0; i
@nagame859
@nagame859 Жыл бұрын
Exceptionally concise👏
@KrishnaKumar-b4m9p
@KrishnaKumar-b4m9p 2 ай бұрын
can u explain how the swap function works here. we want to move all the zeroes in the end how nums[++j]; ????
@KrishnaKumar-b4m9p
@KrishnaKumar-b4m9p 2 ай бұрын
u wanna see my solution?? void Zero_at_last(int arr[], int n){ int i=0; for (int j = 1; j < n; j++) { if(arr[i]==0 ){ if(arr[j]==0){ continue; } swap(arr[i], arr[j]); } i++; // cout
@dhruvpatel0503
@dhruvpatel0503 8 ай бұрын
In move zeroes to end problem we can use this also..., int y=0; for(int i=0;i
@anilkumar4200
@anilkumar4200 Жыл бұрын
Why bro Why, Brute force->better-> optimal, Its really a big effort. thanks for such wonderful video series. Love the way u explain.
@triptisharma5550
@triptisharma5550 5 ай бұрын
Your videos are awesome. I am finally learning to think about a problem and how to approach it. Thank you so much ❤️😬
@thebishalpaul
@thebishalpaul 9 ай бұрын
For left rotate by D places Brute can be : TC: O(n^2) if d==n Hence the rest two solutions shown in video will be better and optimal. int n=arr.size(); while (k>0) { Integer temp=arr.get(0); for (int i = 1; i < n; i++) { arr.set(i-1, arr.get(i)); } arr.set(n-1, temp); k--; } return arr;
@sangeetasharma8574
@sangeetasharma8574 Жыл бұрын
Thank You Striver for such an effort. Your explanations and teaching is really amazing. Its really Valuable /priceless content :)
@AnshulVerma-cd1od
@AnshulVerma-cd1od 10 ай бұрын
Thank you for making such great and useful videos by taking out time from your busy schedule.
@anuragprasad6116
@anuragprasad6116 9 ай бұрын
Concise solution for move zeroes to end: int p = 0; for (int i = 0; i < n; i++) if (arr[i]) swap(arr[p++], arr[i]);
@LearnwithEase20
@LearnwithEase20 Жыл бұрын
Love your explanation sir!You always make things simpler
@chandusweety3341
@chandusweety3341 5 ай бұрын
class Solution { public void rotate(int[] nums, int k) { int n=nums.length; k=k%n; reverse(nums,n-k,n-1); reverse(nums,0,n-k-1); reverse(nums,0,n-1); } void reverse(int arr[],int start,int end) { while(start
@tanishagarwal5992
@tanishagarwal5992 11 ай бұрын
In the three reversals, we are doing iterations just for half the time i.e O(d/2) + O((n-d)/2) + O (n/2) making it O(n) so TC as well as SC of optimal solution is better than the better solution.
@chidambarjoshi3470
@chidambarjoshi3470 Жыл бұрын
In the brute force approach of union of arrays, you could have directly returned the set instead of taking a temp vector and copying it all over, because the set would only take the single copies of the elements are the time of insertion
@nashimbiswakarma
@nashimbiswakarma Жыл бұрын
bro you are right but most of the time they i.e., dsa practicing websites expect you to return the result in the form of array(for c++ vector and for Java ArrayList).
@prateekbhaisora
@prateekbhaisora Жыл бұрын
void rotateright(vector& nums, int k) { k = k % nums.size(); reverse(nums.begin(), nums.end()); reverse(nums.begin(), nums.begin()+k); reverse(nums.begin()+k, nums.end()); }
@harshavardhan184
@harshavardhan184 Жыл бұрын
This much consistency is all we needed bhaiya🤞🤞🤞kudos to you
@karthikjadhav346
@karthikjadhav346 4 ай бұрын
I guess I have an approach for "better" solution for "Move zeroes to end" ( 27:13 ) , correct me if i'm wrong but this is what I got, with T.C O(N+C) int count = 0; for(int i=0;i
@rohandhalpe9084
@rohandhalpe9084 Жыл бұрын
Bhaiyaa ji please upload videos as fast as possible .Our placement season starting soon in June.💫💫💫💫💫💫💫💫💫💫💫💫💫💫
@Hi_kartik
@Hi_kartik Жыл бұрын
Given an integer array nums, rotate the array to the right by k steps, where k is non-negative. class Solution: def rotate(self, arr: List[int], d: int) -> None: n = len(arr) d%=n def reverse1(i,j,arr): while i
@tarun1684
@tarun1684 3 ай бұрын
I gonna fainted..after watching at last that this was easy section..what will happen god in future..bcz I m beginner and finding difficulties 😢😢
@nishantsindhu3420
@nishantsindhu3420 3 ай бұрын
Me too bro similar situation 😢
@sirishayatham1810
@sirishayatham1810 4 ай бұрын
You are making easy for us to understand DSA!! Heartfully Thanks to Striver Brooo
@ParasSharma-mf8or
@ParasSharma-mf8or Жыл бұрын
0:00 Introduction of course 01:01 Left rotate an Array by 1 Place 04:38 Pseudo code 07:17 Code-compiler 08:05 Left rotate an Array by D Places 14:38 Pseudo code 20:18 Code-compiler 27:13 Move zeroes to end 37:41 Pseudo code 40:30 Code-compiler 41:05 Linear search 42:01 Pseudo code 42:43 Code-compiler 43:04 Union of two sorted array 53:33 Code-compiler 59:05 Intersection of two sorted array 1:09:30 Code-compiler
@takeUforward
@takeUforward Жыл бұрын
Thank you Paras!
@ParasSharma-mf8or
@ParasSharma-mf8or Жыл бұрын
​@@takeUforward Welcome and thanks for this amazing course.
@samarthpai5359
@samarthpai5359 2 ай бұрын
for rotaing by right: void rotateR(vector&arr, int k){ int n = arr.size(); reverse(arr.begin(),arr.begin()+n-k); reverse(arr.begin()+n-k,arr.end()); reverse(arr.begin(),arr.end()); }
@Lucifer-xt7un
@Lucifer-xt7un Жыл бұрын
Bro requesting you please upload videos alternatively as promised bcoz completely relaying on you for placements🥺🥺
@NithinvKumar-uk2he
@NithinvKumar-uk2he Жыл бұрын
Yes you are right, striver bro please we are requesting you please upload the video as promised by you 🙏
@takeUforward
@takeUforward Жыл бұрын
I am keeping my promise, if you see am covering 5 problems in one video. So recording such a long video, then editing it, then uploading it takes time. I can upload daily, if you want me to to cover one video.
@NithinvKumar-uk2he
@NithinvKumar-uk2he Жыл бұрын
@@takeUforward ok brother thanks for helping us .we are waiting for upcoming videos ☺️
@harshavardhan184
@harshavardhan184 Жыл бұрын
True
@Lucifer-xt7un
@Lucifer-xt7un Жыл бұрын
@@takeUforward understood ur pain bro thanks for everything.
@Gokul-gkl
@Gokul-gkl 5 ай бұрын
We will have 2 solution one is talking the first 3(in case of d is 3) elements in the temporary array and then making the last 4 elements to the left most and then put back the first 3 elements in the temporary array to the array as you did And the another solution will be FIRST storing the LAST FOUR(which means for(i=d; i
@subhajitmandal1869
@subhajitmandal1869 4 ай бұрын
"THERE IS A ONLY ONE KING IN DSA"
@Mythri333
@Mythri333 9 ай бұрын
Really it is world biggest best dsa course. 😊😊
@SatwikSharma21bcs080
@SatwikSharma21bcs080 5 ай бұрын
✦ Learn left rotation of an array by one place 00:03 ✦ Understand the difference between space used and extra space in algorithms. 06:07 ✦ Learn how to left rotate an array in C++ or Java 18:42 ✦ Left rotate an array by D places 24:15 ✦ Use two pointer approach to move zeros to the end of an array. 34:25 ✦ Summary of array problems 40:19 ✦ Implementing a pointer approach to find the union of two sorted arrays. 50:18 ✦ Union and intersection of sorted arrays 55:30 ✦ Optimize time complexity using two pointer approach 1:06:02 ✦ Optimal solution for intersection of two sorted arrays Click to expand 1:11:14
@Unstoppable.Sakshi
@Unstoppable.Sakshi Жыл бұрын
I have reached here , sir . By following your A to Z DSA course . Thanks a lot sir..
@bipinsingh1490
@bipinsingh1490 Жыл бұрын
Can u tel me is that a fee course or free course?
@Akash-yr2if
@Akash-yr2if Жыл бұрын
Hey Striver, Won't this work fine for the Move Zero's to the end : void moveZeroes(vector& nums) { int i=0; for(int j=0;j
@arunimmalviya1605
@arunimmalviya1605 Жыл бұрын
How do you know if the first index i.e. i=0, will always going to be zero? Also you cannot initiate j from 0, if arr[] = {1,2,3,0}, both I and j will point to 1 and since they both are non zero elements, you are swapping them with themselves only.
@dhruvsolanki4473
@dhruvsolanki4473 Жыл бұрын
Clear explanation and amazing teaching.
@vivek5144
@vivek5144 Жыл бұрын
Hi Striver can you please please upload the notes which you are explaining it will be very helpful 🙏🙏
@RamPageMMA
@RamPageMMA 5 ай бұрын
Take your own notes
@eakanshbhardwaj
@eakanshbhardwaj 9 ай бұрын
43:50 its not i
@suriyavs8685
@suriyavs8685 Жыл бұрын
Hey striver wonderful video. I have a query. The code will be applicable only if the vector or array is sorted in the intersection part. So do we need to sort it again or is there any other optimal approach ?
@VaishaliDhokchawle
@VaishaliDhokchawle 7 ай бұрын
Thanks a lot sir for taking out time from your busy schedule and making videos. It takes a lot of effort. Thanks a lot.
@sudhirdaga3453
@sudhirdaga3453 Жыл бұрын
Right rotate array by d places is equivalent to left rotate array by n-d places. void rightRotateArrayOptimal(int arr[],int n,int d){ d = d%n; d = n-d; reverse(arr,arr+d); reverse(arr+d,arr+n); reverse(arr,arr+n); }
@ayushmittal9666
@ayushmittal9666 Жыл бұрын
It's wrong it should be d=n%d reverse(a,a+n) reverse (a,a+n-d) reverse (a+n-d,a+n)
@rainbowwords6931
@rainbowwords6931 5 ай бұрын
void rotate(vector& nums, int k) { int s = nums.size(); k = k % s; if(k == 0) return; reverse(nums.end()-k,nums.end()); reverse(nums.begin(),nums.end()-k); reverse(nums.begin(),nums.end()); }
@itz_fuzzy6941
@itz_fuzzy6941 9 ай бұрын
Munnawar Faaroqi explaining dsa questions...😂😂😂😂😂
@hidden_star14
@hidden_star14 4 ай бұрын
??
@DeepakKumar-e2s5q
@DeepakKumar-e2s5q 3 ай бұрын
Aisa hai kaide me raho
@itz_fuzzy6941
@itz_fuzzy6941 3 ай бұрын
@@DeepakKumar-e2s5q Ooye Chomu😂 tujhe pta to hai kya bolna chaha rha h tu
@AnasKhan-pm5ys
@AnasKhan-pm5ys 4 ай бұрын
vector rotateArray(vectorarr, int k) { reverse(arr.begin(),arr.begin()+k); reverse(arr.begin()+k,arr.end()); reverse(arr.begin(),arr.end()); return arr; } Striver check it !
@aryankoul1238
@aryankoul1238 3 ай бұрын
Not good way to in interviews rounds
@rish7394
@rish7394 Жыл бұрын
Bhaiya kab tk poora hoga 🥲
@bishalkundu7592
@bishalkundu7592 Жыл бұрын
In a previous post bhaiya said that he will try to cover this course in the next 3 months.
@nikhild.20
@nikhild.20 Жыл бұрын
Reverse Approach Code for Right Rotate:- class Solution { public: void rotate(vector& nums, int k) { int n = nums.size(); k=k%n; reverse(nums.begin(),nums.begin()+n-k); reverse(nums.begin()+n-k,nums.end()); reverse(nums.begin(),nums.end()); } };
@crazyxyzk143
@crazyxyzk143 Жыл бұрын
// right rotation by k places int k;// no of rotation cin>>k; int d = k%n; reverse(arr,arr+(n-d)); reverse(arr+(n-d),arr+n); reverse(arr,arr+n); for(int i: arr){ cout
@PrithaMajumder
@PrithaMajumder 6 ай бұрын
Raj, Thanks a lot for This Amazing Video about C++ Arrays Video - 2 Completed ✅
@udaytewary3809
@udaytewary3809 7 ай бұрын
we can slightly optimise shift 0 to end by using only 2 loops that by first we will construct the temp array as bhaiya created but what additionally we can do is we will maintain a variable count which will store the count of n9.of zeros in the array And then after constructing of temp array we would insert those zeroes at the end of array using a loop or insert as arr.insert(arr.end(), count_zeroes,0) this will insert zeroes at the end of array
@KiritiSrisai
@KiritiSrisai 9 ай бұрын
your explanation is awesome and it is easy to understand
@RaunitJaiswal-s9v
@RaunitJaiswal-s9v 2 ай бұрын
agar kise array ko left rotate kar re hai toh starting from zero index till d index ....and uske baad ka elements ko left lejao and temp array ke elements ko daal do original me ......aur agar kise array ko right rotate kar re hai toh starting from last index till last index-d-1 .....and uske baad ke elements ko right lejao and temp array ke elements ko daal do original me ..........bsc op...raj bhaiya like kardete toh thoda acha lagta
@lost_hand
@lost_hand 7 ай бұрын
Such a great lecture i wouldn't never forget these conceptss❤❤
@chinmaymathakari9704
@chinmaymathakari9704 Жыл бұрын
Thank you so much for taking out time of your busy schedule. Can you please make such videos on Trees as well ? That will be a great help. Thanks a lot😊😊
@senpaidawwwggg
@senpaidawwwggg Жыл бұрын
two pointer approach is great ...
@suprithsk9595
@suprithsk9595 Жыл бұрын
left rotate without extra space: i=0 for j in range(1,n): arr[i],arr[j]=arr[j],arr[i] i+=1 return arr
@harshitbajeta206
@harshitbajeta206 Жыл бұрын
Thank you for all the tutorials till now and much more waiting for the videos of those questions, which are in the A2Z DSA course sheet.
@pranshugoyal1571
@pranshugoyal1571 Жыл бұрын
Alternative solution to move zeroes to end - void moveZeroes(vector& nums) { int i = 0, j = 0; while(j < nums.size()){ if(nums[j] == 0){ j++; } else{ swap(i, j, nums); i++; j++; } } }
@ayansiddiqui7383
@ayansiddiqui7383 Жыл бұрын
can you explain the logic behind this please
@abhishekjadhav2250
@abhishekjadhav2250 2 ай бұрын
conscise solution for move zeroes to end class Solution { public: void moveZeroes(vector& nums) { int n = nums.size(); int j = 0; for (int i = 0; i < n; i++) { if (nums[i] != 0) { swap(nums[i], nums[j]); j++; } } } };
@Codro09
@Codro09 8 ай бұрын
26:06 for right shift int n = nums.size(); k = k%n; //temp varible to store the values which are n-d from left vector temp; // int temp[]={}; for(int i = n-k;i=0;j--){ nums[j+k] = nums[j]; } //Put back the elements of" temp" int z = 0; for(int l = 0;l
@sunnymishra2120
@sunnymishra2120 Жыл бұрын
I'm really lucky to have you as a teacher
@pritishpattnaik4674
@pritishpattnaik4674 Жыл бұрын
Incase somebody need the code for right rotate , it is in Leetcode rotate array Solution : void rotate(vector& nums, int k) { int n = nums.size(); k = k % n; vector temp; for (int i=n-k ; i=0 ; i--){ nums[i+k] = nums[i]; } int j = 0; for (int i=0 ; i
@saumyasarngal6109
@saumyasarngal6109 Ай бұрын
Thanku
@Himani-t3g
@Himani-t3g 2 ай бұрын
understood! really like the relatable example of relationship🤣🤣 thank you for your efforts
@vivekbharadwaj4170
@vivekbharadwaj4170 Жыл бұрын
I wish I could get to know about your course in my first year, I'm in second year now, not late, btw thanks a lot (UNDERSTOOD)
@cinime
@cinime Жыл бұрын
Understood! Fantastic explanation as always, I've enjoyed the video. Thank you very much!!
Beginners Should Think Differently When Writing Golang
11:35
Anthony GG
Рет қаралды 123 М.
FOREVER BUNNY
00:14
Natan por Aí
Рет қаралды 25 МЛН
МЕНЯ УКУСИЛ ПАУК #shorts
00:23
Паша Осадчий
Рет қаралды 5 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 93 МЛН
Programming Languages Tier List 2024
16:18
Neal Wang
Рет қаралды 11 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 688 М.
Merge Sorted Arrays Without Extra Space | 2 Optimal Solution
32:47
take U forward
Рет қаралды 215 М.
New Thrower Troop, Firespitter Defense and Revive Spell in Clash of Clans!
18:35
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 438 М.