Bhaiya aap jaise 1-2 utubers aur aa jaye..fir coding blocks aur ninjas to katora lekrr ghumenge.... U r a big support for the students like me who cannot afford those extremely expensive courses. Request h ki aap continue krtee rhoo... Plzz.... 🤣
@thexhist36093 жыл бұрын
We also have pepcoding which is good and everything is free.
@tanned_cosines_3 жыл бұрын
lmfaoooooo
@mishorpatra16703 жыл бұрын
"Once you learn to approach problems, you'll stop running after the solution." - Sir Aditya Verma (bas ab ek backracking aur graph playlist banado aur kuch nahi chahiye)
@amarnathprasad13 жыл бұрын
Until he makes one, you can watch the first six lectures from here and solve questions from the FreeCodeCamp video(7th video in the playlist). I got better at graphs after practicing questions from the FCC video. kzbin.info/aero/PLmqutD5ta9PvsMYCyc0tVpmIl8-iIgxey
@nitwaalebhaiya3 жыл бұрын
@@amarnathprasad1 Thanks
@Adarsh-mn7pl2 жыл бұрын
bul ja, ab kuch nhi ane wala
@nidhishprasad25062 жыл бұрын
@@Adarsh-mn7pl why?
@mantenapragnyabala17116 ай бұрын
Hi do you know from where to do queue@@amarnathprasad1
@govindsharma69519 ай бұрын
can not explain how much happy i am after finding your channel. thank u so much for creating these videos
@upasanaarora26414 жыл бұрын
for almost 1 month searching for new fresh content to revise my concepts again,loved your channel.Its has all,what it needs to be done even in short time,To the point and great content.Great Job :)
@Area-fd8ht Жыл бұрын
❤
@karanbhati75523 жыл бұрын
More Concise code :: vector nextLargerElement(vector a, int n){ stack s; vector ans; for(int i=n-1;i>=0;i--){ while(!s.empty() && a[i]>=s.top()){ s.pop(); } if(s.empty()) ans.push_back(-1); else ans.push_back(s.top()); s.push(a[i]); } reverse(ans.begin(),ans.end()); return ans; }
@pragyanshandilya40152 жыл бұрын
legend
@charugoswami5344 Жыл бұрын
Kindly help me to find error in this code.... vector nextGreaterElements(vector& nums) { stacks; vectorv; for(int i=nums.size()-1;i>=0;i--){ while(!s.empty() && s.top()
@_AmbujJaiswal Жыл бұрын
bhati bhai thankyou soo much
@samikshayadav3475 Жыл бұрын
good good
@manjeshpatil Жыл бұрын
So basically at n-1 checking your code executes the while loop first even though the stack is empty that's y write the if condition 1st then else then the while loop. Correct me if iam wrong @@charugoswami5344
@hereyoursdad2 жыл бұрын
sir more then that the little talk from your exeperience like what they want from us is really a diamond .. thank you so much for making these gems will help so many peoples
@comps_52_mankritsingh843 жыл бұрын
*Interesting thing to note* For those who are getting segmentation error even though your code is the same check whether you have done the seek or top operation on the stack in your code? for eg in the code while(s.top()0) In this code when the stack is empty the first condition will be checked first and give you segmentation error.Instead, keep the statement after the empty check and the error will go. Hope it helps ;)
@abhijeeyt2 жыл бұрын
bhai 🙏🙏
@Lucifer-jl9vh2 жыл бұрын
Thank you bhai
@pranjalmukherjee2 жыл бұрын
Thank you bhai
@tanya25862 жыл бұрын
heyy.. i'm still getting error.. can you check why? vector v; stack s; for(int i=n-1;i>=0;i--){ if(s.empty()){ v.push_back(-1); } else if(s.top()>arr[i]){ v.push_back(s.top()); } else if(arr[i]>=s.top()){ while( s.size()>0 && arr[i]
@comps_52_mankritsingh842 жыл бұрын
@@tanya2586 try by removing that ! Sign in the last check you have put if(!s.empty()) .
@TechnicalDrMusicАй бұрын
Literally your DSA teaching approache is 🔥 than all others KZbins, big thank you ❤
@pratikkedar44762 жыл бұрын
Small Optimization : We can avoid using reverse method, just need to push elements from array in reverse order ! Make sure you define fixed vector length else will give compilation errors!!
@pokeindia5361 Жыл бұрын
Why is this so we don't need size of vectors ryt?? I'm facing this problem
@Demodulator7 Жыл бұрын
@@pokeindia5361 we need size of answer vector and it will be equal to given vector
@pokeindia5361 Жыл бұрын
@@Demodulator7 I'm asking why we need to fixed vector length vector is automatically adjusted on its own ryt??
@Demodulator7 Жыл бұрын
@@pokeindia5361 but in optimization, you are filling vector from backward (so that you not need to reverse it) so you have to give the length that from where you are filling. And you can't use push_back because it adds value in last, but each time you want to add values at front because first you calculated value for I = n-1 (last element) and then for i= n-2 (second last element) and so on till the first element. So you have to do V[i]= .... So you have to give vector a size because vector can increase it's size in one direction only. If you directly do V[n-1] =.... Then it will give runtime error because vector is trying to access n-1 position but currently vector size is 0. One more point:- doing push_back doesn't require size declaration. But when ever you do V[I] = .... Then size of vector should be greater then I. If not want to declare size then you can use 'list' and do push_front Hope it helps...
@pokeindia5361 Жыл бұрын
@@Demodulator7 thank u so much sir!!
@shubhamjain545192 жыл бұрын
14:18 for context. 15:19 2 can be safely popped because we have already found an element on its left which is greater than 2, ie 3. As any element (greater than 2 and smaller than 3) on left of 3 which needs next greater element on its right will always print 3, so 2 is of no use at this point.
@williamgilfoyle32612 жыл бұрын
Best explanation so far, but i would prefer "while loop" over "for loop" , for current problem and in the third if case we dont move to the next element in the array until we pop all the elements from array Like here Python : Language arr = [1,3,0,0,1,2,4] stack = [ ] res = [ ] i = len( arr ) - 1 while i>=0: if not stack: res.append(-1) elif stack[ -1 ]>arr[ i ]: res.append(stack[-1]) elif stack[ -1 ]
@sushmitamandal1677 Жыл бұрын
my programme is not running can you please help to run the code?please
@abhijeetgupta34614 жыл бұрын
reverse(v.begin(),v.end()) after for loop ...
@akashdawari46654 жыл бұрын
continue bro, this good work ;)
@TheAdityaVerma4 жыл бұрын
Thanks brother, Do subscribe and share, that keeps me motivated to do more !!
@samirsaurabh57853 жыл бұрын
@@TheAdityaVerma please make such great videos on all data structures and algortihms,you are the true mentor ❤️.
@nandasaikishore4783 жыл бұрын
@@TheAdityaVerma please continue the course sir please 🙏🙏🙏
@souravsaha34463 жыл бұрын
@@TheAdityaVerma Brother please upload videos on some other topics please You are not only a teacher to me but also a coding guru who can teach with his experience please sir upload on backtracking and graphs
@adarshanand1764 жыл бұрын
this is ur first impression on me... and its really looks like my dream teaching style. 🤩✌
@adityachauhan995110 ай бұрын
best explanation available on KZbin thank you so much
@RohithRock4 жыл бұрын
Crystal clear explanation bro. Really it helped me a lot in understanding the concepts perfectly. I was really afraid of datastructures and algorithms. I was not able to solve the questions thinking that ds is a really tuff subject. But now through ur way of teaching and explaining i am able to learn and understand easily. Thank you bro. Do more videos regarding the ds topics. From - rohith Nit bhopal cse
@piyushaggarwal784 жыл бұрын
Initial if and elseif condition are not required as it is redundant., Very good explanation of things, great content. Waiting eagerly for Trees and Graphs and Number theory.. I always prefer watching your videos on 2x speed , it sounds perfect that way
@SurajKumar-bw9oi4 жыл бұрын
Right bro, Code written After while loop started is sufficient 👍
@pranjalsrivastava11914 жыл бұрын
true, no use for the first two conditions. Already covered by the portion after while!
@Codermonk19974 жыл бұрын
guys like u should be kicked on their arse, dumbo if u are so intelligent then go and try to get jon in mnc instead of watching his vidio. he is teaching how to convert ur idea into code, one if elsse will not going to increase time complexity to exponential. idiots like you exist every where.
@arunavgoel56203 жыл бұрын
@@Codermonk1997 Damm, the guy just pointed out another way to write the code, a way which reduces the number of lines and also makes the code run more efficiently...no need to get triggered by that
@harjos784 жыл бұрын
loved watching your videos.. Awesome .. crystal clear explaination. Was refreshing my DS concepts to teach my son who is in 7th grade. Now after he has watched your videos he says your explaination is way better than i can explain him.. Kudos Aditya. Keep up the good work. God bless you
@ankitsharda11312 жыл бұрын
With due respect to you I would suggest you to let your son enjoy his childhood. All this he can learn it when it will be the right time.
@vanshshah7781 Жыл бұрын
7th grade is too late man
@vathsan39064 жыл бұрын
Bhai.. Sorry I would like to call you SIR.. Hats off.. I was scratching my head for the past 2 days trying to figure out why they are using stack, how to identify what to use and when to use and also to get the approach to solve... I was unable to understand it from GFG and thank god I found you!! Finally understood why we are using stack and what is it's purpose in this question...
@rushikesh_chaudhari4 жыл бұрын
Just started watching your playlist and this is really mind blowing. Loved your way to find solution for problems
@AyushGupta-ux4gq Жыл бұрын
what are you doing now after 3 years of this comment ??
@abhishekojha45402 жыл бұрын
brother I was stuck in this question for so long time and no one has explained this question to me in so much detail. Thanks a lot.
@SauravKumar-si7kt3 жыл бұрын
This is sth which i need in other youtube solutions. I never got satisfied with their solution because they are just discussing the solution. And those solution never helped me. Thank you for introducing these all concept. It would have taken a lot of time to think on our own.
@theunusual45662 жыл бұрын
Matlab, Kamaal Ka explanation bhai. Automatically understood next 3 questions. Bahut Khood Samjhaya Aapne. Thanks.
@ShahNawaz-cx3pi3 жыл бұрын
*********Time complexity Doubt:-******** I got what you want to ask:- your main concern is about the inside while() loop, you are thinking that it will become O(n^2) , but this will never happen the worst case complexity can be O(2n) , in simple terms O(n) . Case 1 :- arr [] :- 6 5 4 3 2 1 In this case the while() loop will run only one time in each iteration of for() loop so, while() loop is contributing only O(1) complexity. In this case it is simple O(n). Case 2:- are[]:- 6 1 2 3 4 5 In this case every element in the array will considered 2 times. First time when we are traversing the array in backward direction through for() loop and another time when we traverse element in forward direction through while() loop. It is just like traversing array two times O(n) +O(n) =O(2*n). So, The overall complexity become O(2n) ~ O(n).
@tiyashadas52473 жыл бұрын
Thank you!
@sanyam97123 жыл бұрын
Thankyou
@kingrajput62023 жыл бұрын
thanks man
@PankajSingh-vi3fy3 жыл бұрын
For me it's kinda tricky but got your point thanks
@rajatagarwal60912 жыл бұрын
Hi @Shah Nawaz. Thanks for your explanation. However I still have a doubt that worst case complexity would be O(n^2). let consider some array like 20,14,15,16,17,18,19, 10,7,8,9 , 6,1,2,3,4,5. What are your thoughts on this array?
@bestsaurabh4 жыл бұрын
Instead of taking vector we can take array start filling it from end, this way we can save reverse function call.
@aayush54744 жыл бұрын
you can also do like vector v(n);
@malkeetsapien48522 жыл бұрын
Brilliantly taught Sensei !
@nirbhay4114 жыл бұрын
Bhai kya hi samjhaya he apne . maja agaya
@utsavseth6573 Жыл бұрын
Not all heroes wear capes. Some are named aditya verma. Superb.
@amankumar-im8kk4 жыл бұрын
Awesome content. You will be hitting 1M subscribers soon. Far better than paid contents of coding blocks and coding ninjas.
@niveditaprity4 жыл бұрын
Impeccable and great explanation. Please upload more videos on tree and graph also.
@NotNotNithin3 жыл бұрын
Java implementation: private static List nearestGreatestToRight(int[] arr) { Stack st = new Stack(); List reverseList = new ArrayList(); List resList = new ArrayList(); int size = arr.length; for (int i = size - 1; i >= 0; i--) { if (st.empty()) { reverseList.add(-1); } else if (st.size() > 0 && st.peek() > arr[i]) { reverseList.add(st.peek()); } else if (st.size() > 0 && st.peek()
@ayush75182 жыл бұрын
thanks a lot bhai
@salonipaliwal8946 Жыл бұрын
thank you
@RohitKumar-uc4fw Жыл бұрын
Use this code to directly store from right to left. public static int[] findNextGreater(int[] ar) { int[] result = new int[ar.length]; Stack stack = new Stack(); for(int i = 0; i < ar.length; i++) { while(!stack.isEmpty() && ar[i] > ar[stack.peek()]) { int index = stack.pop(); result[index] = ar[i]; } stack.push(i); } while(!stack.isEmpty()) { int index = stack.pop(); result[index] = -1; } return result; }
@shivagupta138 Жыл бұрын
@@RohitKumar-uc4fw use this and you wont need to reverse it even " public static int[] nearestright(int []arr) { Stack stack=new Stack(); int result[]=new int[arr.length]; for(int i=arr.length-1; i>=0; i--) { if(stack.size()==0) { result[i]=-1; } if(stack.size()>0 && stack.peek()>arr[i]) { result[i]=stack.peek(); } if(stack.size()>0 && stack.peek()0 && stack.peek()
@alexamish20204 жыл бұрын
Ye channel bhot zyada grow krege. Gauranteed.
@lavanyabalija6994 жыл бұрын
Before listening to your lectures , am unable to write the code at 1 stretch, it used to take lot of time to debug my code. Am glad i found ur channel broo...Now am able to write code with ease. Thanxxxx for ur methodology of making coding soo easyy...Plss make more n more videos. If possible make videos on all topics of CP.
@animeshsingh28803 жыл бұрын
Best videos in youtube for learning DSA
@hackzyoboy24594 жыл бұрын
165th like, 0 dislikes. That's the power of generous teaching. Great job bhaii
@jhanvisaraswat69763 жыл бұрын
Those three conditions putting things in perspective so much
@akarshjaiswal16224 жыл бұрын
Great explanation... Please start uploading videos again... Looking forward for mathematics, backtracking,graph videos !
@priyaagrawal29682 жыл бұрын
One of the very best explanation! Thanks Aditya !
@aheribanerji70563 жыл бұрын
Pls, sir make more videos... it's very helpful for students like us who can't afford the high prized course .
@mystryb3454 жыл бұрын
Completed heap,dp,recursion now i m.feeling confident thanks bro ...
@mohdhasnain38123 жыл бұрын
you have studied from his channel or some where else please confirm that all the stutff you have studied in this channel is on point , effective nd easy to unxderstand
@thinkingmad16853 жыл бұрын
@@mohdhasnain3812 have you found some other channel, pls suggest btw i m feeling comfortable to understand from this channel only 🥲
@r4ncreation686 Жыл бұрын
best explaination of stack till date
@___vandanagupta___3 жыл бұрын
Your every video is a blessing!
@RajveerSingh-yf1os11 ай бұрын
THIS IS MY FIRST YT COMMMENT IN MY LIFE JUST LOVES THIS VIDEO
@AnkitKumar-rh8il4 жыл бұрын
maza aa gya bhaiya , aapka explain karne ka tareeka OP hai
@rishabsharma53073 жыл бұрын
Little more simpler version of code // nearest greater to right vector ngr(vector arr, int n) { stack st; vector vect; for(int i = n-1; i >= 0; i--) { while(!st.empty() && arr[i] >= st.top()) st.pop(); st.empty() ? vect.push_back(-1) : vect.push_back(st.top()); st.push(arr[i]); } reverse(vect.begin(), vect.end()); return vect; }
@rishabsharma53077 ай бұрын
Slightly better approach with no vector reversal ``` vector ngl(vector &nums) { stack st; int n = nums.size(); vector result(n, -1); for (int i = n - 1; i >= 0; i--) { while (!st.empty() && nums[i] >= st.top()) st.pop(); if (!st.empty()) result[i] = st.top(); st.push(nums[i]); } return result; } ```
@avinashsaklani3 жыл бұрын
great explanation
@abhishekanantharam6453 жыл бұрын
O bhai legend aadmi hai ye toh. Thanks✌️
@_solopreneur3213 жыл бұрын
bhaiya u rocked its great to be learning from ur videos keep adding value. Very helpful videos.
@vinayakrastogi8904 жыл бұрын
Bro I am waiting for your backtracking playlist... I know you have a busy schedule but please make videos on that
@riaria59824 жыл бұрын
Great Explanation! To improve runtime performance don't do reverse, it's better if you insert element : for(int i=input.length-1; i>=0; i--) { while(!stack.empty() && (stack.peek()
@nishant52494 жыл бұрын
your code is not absolutely correct
@saumitrashukla5914 жыл бұрын
@@nishant5249 why? it seems correct
@AdamRubiks3 жыл бұрын
oh damn
@RohitKumar-uc4fw Жыл бұрын
Use this code to directly store from right to left. public static int[] findNextGreater(int[] ar) { int[] result = new int[ar.length]; Stack stack = new Stack(); for(int i = 0; i < ar.length; i++) { while(!stack.isEmpty() && ar[i] > ar[stack.peek()]) { int index = stack.pop(); result[index] = ar[i]; } stack.push(i); } while(!stack.isEmpty()) { int index = stack.pop(); result[index] = -1; } return result; }
@Newgen123Blogspotawaytosuccess4 жыл бұрын
These are the best video series that is available till Date. Also, make your account premium so that you can continue your work in a more focussed manner. Great work. Ready to pay thousands for such beautiful content.
@akashverma575611 ай бұрын
Best Explanation of this problem online
@ROHIT-gv7xk4 жыл бұрын
great work bro god bless you
@shrutirani68284 жыл бұрын
Please make more videos for placement prep... Ur videos are helping a lot.. Great mannn...
@mohitsingh6717 Жыл бұрын
best channel on youtube 🙂
@souravrajvi81932 жыл бұрын
THIS IS FUNCKIN LEGENDARY
@Akshat-tz2de Жыл бұрын
Just a small doubt if we have used only 2 loops and used break in 2nd loop when condition is met then also we could have attained same complexity. As you are also using while loop inside for loop which is running for same time that the another for loop will run and for same amount of iterations. Moreover we are using stack here hence increase in space complexity as well.
@rahulagarwal80594 жыл бұрын
Wow.... Really happy that i found ur channel... The videos are very helpful👍
@annuagarwal84382 жыл бұрын
I am lucky to find your videos. Thank you for making such helpful videos. Your experience will be helpful to lot of people. Please make videos in graphs and backtracking also. I know you wont have much time. But ek mahine mai do video hi daal dena..We will wait. Thanks again😇
@keshavdutttripathi3 жыл бұрын
Great work bhai. Really helpful
@satyamshukla14183 жыл бұрын
this is a gem of a content.thanks a lot for this bhaiya apne hisaab se time nikal krke agar aap backtracking graph par agar videos bana denge toh humari aur help ho jayegi.
@shashijaiswal50143 жыл бұрын
I will complete this playlist by tomorrow. 4 hr approx for this and 2hr per day. Will comment tommorow on last video of this playlist.
@ajeetworking4 жыл бұрын
Thank you for the explaination. We can also approach this without reversing the array as vector nextLargerElement(long long arr[], int n) { stack stk; stk.push(0); vector ans(n, -1); for (int i = 1; i < n; i++) { while (!stk.empty() && arr[stk.top()] < arr[i]) { ans[stk.top()] = arr[i]; stk.pop(); } stk.push(i); } return ans; } in this, we push the element in the stack only if it is smaller than the previous element and if next is greater then we start popping until no further element is greater than the current element.
@sayantaniguha85194 жыл бұрын
non linear time complexity
@375_rishavmishra94 жыл бұрын
Bro ur great one of best teaching style.♥️♥️hope that you will continue with graph and trees also.
@NitinKumar-sx6jl2 жыл бұрын
Please continue the series bhaiya great work
@anveshkhambadkar6821 Жыл бұрын
Awesome content, Awesome Explanation Man.
@Tanm06093 жыл бұрын
very good explanation brother,keep it up and keep uploading
@rohitjha9714 жыл бұрын
Please tree and graph bhi padhao
@TheAdityaVerma4 жыл бұрын
Will try !!
@nikhilnagrale4 жыл бұрын
@@TheAdityaVerma backtracking!!!!!!!!!1
@manjeetkagada75343 жыл бұрын
You are on next level man
@shubhamdevrani72514 жыл бұрын
Hey bro just loved ur solution for the problem...
@garimadubey89704 жыл бұрын
Thank you sir its very helpful vedio for us..nice explanation.
@NidhiSharma-sw4oz2 жыл бұрын
How O(n) complexity ????? There is a while loop inside for loop. So how it is O(n) complexity ?
@sandip_kanzariya84762 жыл бұрын
Head's of brother 👌🙏
@muhammedrameez6523 жыл бұрын
Great Work bro! It really helped me
@jatinkumar44102 жыл бұрын
amazing explanation....
@tusharjain56583 жыл бұрын
really this explanation is amazing
@vrandakansal59404 жыл бұрын
Bro!!...Great work...😄😄👌
@ayushgupta8538 Жыл бұрын
*Thank you so much for this awesome video.*
@abhishekrai4002 Жыл бұрын
bhai gajab maja aagya
@UpscWithPavanOfficial9 ай бұрын
Nice, Mza Aaya bhai.
@kapishsingh3 жыл бұрын
its the first chanal in which i done like share and subscribe in less than 1 ms
@NikhilTripathy3 жыл бұрын
17:00 this is gem!
@koushik78574 жыл бұрын
fabulous explanation!!!!
@RicheshGuptaRichu3 жыл бұрын
Mann karta hai pdhne ka..Aesi videos dekh kar
@vinayverma30993 жыл бұрын
Isn't this also O(n^2) solution because of while loop inside a for loop.??
@adityakainthola29533 жыл бұрын
no every element is traversed atmost 2 times in both the loops so the complexity will be O(n)
@varshithkemmasaram21153 жыл бұрын
@@adityakainthola2953 i did not understand bro🥲🥲
@shashankdaima87273 жыл бұрын
@@varshithkemmasaram2115 The reason this method works is because he pops every element b/w arr[i+1] to arr[n-1] which are less than arr[i] until he reached a position that is greater than arr[i] or stack becomes empty. For eg:arr:{9,7,6,5,3,2} (Strictly Decreasing sequence). Initial Stack(right should be considered as top){-1}. For last element of arr. the ans is -1 and stack becomes {-1,2}.For second last element, we will check for element greater than current element. So, currentElement=3. Stack{-1,2}. (2Pop(2); stack contains -1 so return -1. now if you move to next Element you need to push 3 into stack making{-1,3}. So, we never have to deal with 2 again. That why the complexity is O(n). as Complexity is ranging b/w n to 2n so O(n)
@aryannegi94143 жыл бұрын
@@shashankdaima8727 but arent there two loops in this solution too?1st for i=n-1 to 0 and inside it while(!stack.empty&&stack.top()
@VENDETTA_911 ай бұрын
For circular array: #include using namespace std; vector nextGreaterElement(int N, vector& arr) { stack s; vector ans; for(int i=2*N-1; i>=0; i--) { if(s.empty()) ans.push_back(-1); if (!s.empty() && s.top() > arr[i%N]) ans.push_back(s.top()); else if (!s.empty() && s.top()
@saitejdandge23154 жыл бұрын
Great lecture I got an intuition that we are using sub problem solutions to form solution current index i (Optimal substructure) and we have repetitive sub problems which is causing O(n*n). This is a dynamic programming, correct me if I'm wrong.
@supritchafle37064 жыл бұрын
best explanation on stack quns...
@rajanoobrigaming14504 жыл бұрын
Very helpful video vaiya ...help me lot
@SanjuKumar-ye8xz3 жыл бұрын
Brother, tumne alag se vector define kiya jisase eski space complexity increase ho rhi hai.
@Sithkar03 Жыл бұрын
Coding Ninja : Next Greater Element ( C++ Solution ) #include vector nextGreaterElement(vector& arr, int n) { // Write your code here vector ans; stack st; for(int i=n-1;i>=0;i--){ while(!st.empty() && st.top()
@redwanniloy20684 жыл бұрын
U did not show how stack's elements are storing in stack..in code...but i understand everything.. Thanks brother❤️
@prerna.please3 жыл бұрын
can you tell me , how the elements are storing?
@daddyjee61373 жыл бұрын
U deserve more 🎉 ❤️❤️
@bhawnabharti43693 жыл бұрын
best explanation
@wrushu4 жыл бұрын
If we have the same question for cyclic array like.. instead of having -1 for arr[n-1] we need to look at the 0th element. What would you suggest? What I came across is to traverse the loop 2 times. for(i=2*n;i>=0;i--) and reference ith element as i%n
@pranjalmishra26024 жыл бұрын
So un the worst case how is the complexity O(n) ? If has inner while loop as well... Should be N square in worst case right?
@pranjalsrivastava11914 жыл бұрын
correct ... even i have a doubt in this....the inner while loop can go till n and thus worst case complexity would be n square.... the same case would be when we use 2 for loops ....please explain someone!
@pranjalmishra26024 жыл бұрын
@@pranjalsrivastava1191 😶 👍🏻
@harshashenoy85554 жыл бұрын
Guys, while loop is over the stack And stack holds only the greatest element. Worst case happens only for one iteration where in the smaller elements gets popped. And for the next iteration the previous iteration value will be on top . So using this method the time complexity would be O(n). Try an example to understand more.
@aniketsinha28262 жыл бұрын
greatly explained !!!
@AdityaLSharma2 ай бұрын
Any possibility I can get all these notes in PDF form?
@rohitmaheshwari93573 жыл бұрын
bhaiya vector ko reverse krne ki jarurat nahi h ek pointer last se chla ke answer fill kr dete h tb bhi kaam chl jayega