Next Greater Element | Two Variants | Leetcode

Поділитися
Вставка
  • Опубліковано 5 жов 2024

КОМЕНТАРІ • 231

  • @takeUforward
    @takeUforward  3 роки тому +242

    While writing code, it should have been.. 2n-1 to 0 😅
    You can also do by front passing, but that will take more time, as you have to store index, and then retract them.. leetcode.com/problems/next-greater-element-ii/discuss/98270/JavaC%2B%2BPython-Loop-Twice

    • @kakoli960
      @kakoli960 3 роки тому +31

      I am in comment section just to check that if I am only not understanding or the code had mistakes.. thanks for this

    • @hh8xking30
      @hh8xking30 3 роки тому +3

      @@kakoli960 and we too have to reverse the output array as we are doing operations from last. and we have to show output from first.

    • @akshayzade9761
      @akshayzade9761 2 роки тому +20

      Thanks @Striver
      Correction 1 - for(int i=((2*n)-1); i>=0 ; i--)
      Correction 2 - while( (!stack.isEmpty()) && (stack.peek()

    • @subhampandey7374
      @subhampandey7374 2 роки тому

      😄

    • @SwapnilSarkar
      @SwapnilSarkar 2 роки тому +8

      This mistake wasted so much of my time

  • @nikhilpatro5905
    @nikhilpatro5905 3 роки тому +235

    Dude, you have such good teaching skills! I have been a TA at coding ninjas so I know how hard it is to explain an algorithm. Please never stop teaching :)

    • @akshitkumar9402
      @akshitkumar9402 2 роки тому

      > I have been a TA at coding ninjas
      literally nobody asked

    • @mudrad1930
      @mudrad1930 2 роки тому +41

      so a coding ninja TA also using free resources 😂😂

    • @vishal40007
      @vishal40007 2 роки тому +9

      @@mudrad1930 There always something new to learn

    • @allhdmoviescene1294
      @allhdmoviescene1294 Рік тому +8

      no more learning from coding ninja

  • @kritidiptoghosh4272
    @kritidiptoghosh4272 2 роки тому +100

    Really good explaination. Just wanted to add something for those ,who are still not 100% sure about why the stack technique is working.
    Just Think of the numbers as poles casting shadow(To their right,bcoz we see from left ).
    Lets say the next larger pole for a particular index is L. Because we are looking from the left side, when we see L we will not be able to see the poles on its right which are smaller than L because they are overshadowed. But the poles on L's right which are larger than L can still be seen because they are taller. (Thats why they are in stack).
    The stack at any position is literally what we would see standing there looking at right.

    • @abinvarkey2331
      @abinvarkey2331 Рік тому

      thanks for that tip :)

    • @tear7934
      @tear7934 Рік тому +1

      woah really nice intuition!! thanks

    • @amogu_07
      @amogu_07 6 місяців тому +1

      thanks so much !! that's an awesome intuition !!

  • @thor1626
    @thor1626 8 місяців тому +44

    the loop cond should be
    for (int i = (len * 2) - 1; i >= 0; i--)

  • @nayanbhuyan8156
    @nayanbhuyan8156 3 роки тому +36

    To make things even more simpler, if(i < n) condition is not required, instead write i % 2 in other steps, like:
    vector nextGreaterElements(vector& nums)
    {
    int n = nums.size();
    vector res(n);
    stack st;
    for(int i = 2 * n - 1; i >= 0; i--)
    {
    while(!st.empty() && nums[i % n] >= st.top())
    st.pop();

    if(st.empty()) res[i% n] = -1;
    else res[i % n] = st.top();

    st.push(nums[i % n]);
    }
    return res;
    }

    • @babai2196
      @babai2196 2 роки тому +2

      thanks bro

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      for first variant why we running for 2*n-1 ... it should be done only for circular onces !!

    • @pranavsharma7479
      @pranavsharma7479 2 роки тому

      @@PIYUSH-lz1zq no for first run for n-1 to 0 only

    • @amanbhadani8840
      @amanbhadani8840 2 роки тому +1

      This code allows same values to be reassigned,thats not logical and not prefered.

  • @spandanrastogi7144
    @spandanrastogi7144 Рік тому +23

    Awesome explanation !
    In Code, I think by mistake Loop is iterating from left to right when it should be iterating from right to left.

  • @adwiteek5936
    @adwiteek5936 4 місяці тому

    Avoid using maps in these circular array types of questions as you might get wrong answer by storing different value for same key in a map..... you can directly return the vector on leetcode when you will be iterating from i

  • @harshalgarg1149
    @harshalgarg1149 3 роки тому +11

    Another approach that can be used is that first we put all the elements in stack while traversing backwards from the end and then use the same code that was used for the first variation.
    vector nextGreaterElements(vector& v)
    {
    vector vans;
    int n = v.size();
    stack st;

    for(int i=n-1;i>=0;i--)
    st.push(v[i]);

    for(int i=n-1;i>=0;i--)
    {
    while(!st.empty() and st.top()

  • @akshaykenjale2642
    @akshaykenjale2642 2 роки тому +1

    In Next Greater Elements problem I guess instead of i

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      for first variant why we running for 2*n-1 ... it should be done only for circular onces !!

    • @amanbhadani8840
      @amanbhadani8840 2 роки тому

      @@PIYUSH-lz1zq Not required for first variant bro.

  • @maccall0108
    @maccall0108 3 роки тому +11

    brother we can also store array index from n-2 to 0 in stack and then apply the similer logic as we have applied in Ques ->next-greater element -I and before returning our vector we just need to reverse it.
    vectorv;
    stacks;

    int siz=nums.size();
    for(int i=siz-2;i>=0;i--)
    {
    s.push(nums[i]); //store from n-2 to 0 in stack
    }

    for(int i=siz-1;i>=0;i--)
    {
    if(s.empty()==1)
    {
    s.push(nums[i]);
    v.push_back(-1);
    }
    else
    {
    while(s.empty()!=1 && (s.top()

  • @udayptp
    @udayptp 3 роки тому +22

    Bhai kal hi mere coding round mein ye question pucha tha,
    1- next greater element
    2- make largest no using all element of the array

    • @chandankumarshaw216
      @chandankumarshaw216 3 роки тому

      which company

    • @udayptp
      @udayptp 3 роки тому +4

      @@chandankumarshaw216 Thinkitive technologies

    • @udayptp
      @udayptp 3 роки тому +6

      @@chandankumarshaw216 package 4.5lpa

    • @Carson00_11
      @Carson00_11 6 місяців тому

      @@udayptp bhai abhe kya kar rhe ho

    • @udayptp
      @udayptp 6 місяців тому +1

      @@Carson00_11 D. E. Shaw and Co.

  • @cricedge4454
    @cricedge4454 2 роки тому +9

    bhai for(i=2*n-1 .......) hoga ..but u have written for(i=0..)

  • @ineerajnishad
    @ineerajnishad 2 роки тому +6

    Maaannn, Striver you're certainly best in what you do, which is TEACH things so so smoothly! Big thanks Sir❤

  • @somratdutta
    @somratdutta 3 роки тому +7

    I wish we had such teachers! 😢😍

  • @snehilsinha4689
    @snehilsinha4689 3 роки тому +13

    Best possible explanation! The concept gets stuck in my mind forever after watching this 🔥. tysm striver bhaiya 💓

  • @karanthakkar9009
    @karanthakkar9009 3 роки тому +5

    Hii bhaiya, recently I came into a problem called "Sherlock and the maze" tags: memorization & DP. I really did not understood how to slove problem, when I saw the editorial it was really confusing, I also saw other's people submission, but everyone had submitted in scala,haskell language. Could you make a video on that problem?

  • @rishabhkumar8115
    @rishabhkumar8115 3 роки тому +2

    bro hats off to you...you have brought this new institution for circular array..Before this I don't about this.
    Thankx to be our menntor

  • @adityasethi9794
    @adityasethi9794 Рік тому +2

    I think code has an error. Why do we start form left and go till right. Aren't we supposed to start from end and do i-- ?

  • @adarshbadagala
    @adarshbadagala 3 роки тому +4

    Thank you so much for such an excellent explanation
    but I have small doubt instead of writing an if condition inside loop can we just use i%n for nge too?
    i mean instead of writing
    if(i

    • @JujareVinayak
      @JujareVinayak 2 роки тому +1

      Yes

    • @arjunrai8126
      @arjunrai8126 2 роки тому +1

      Yes u can

    • @AbhishekKumar-vr7sh
      @AbhishekKumar-vr7sh 2 роки тому +2

      U can and it will still pass the test cases but its not needed bcoz anyways its gonna get replaced when we process elements in range i = 0 to n-1

    • @adarshbadagala
      @adarshbadagala 2 роки тому +1

      @@AbhishekKumar-vr7sh thank you for clarifying

  • @Anonymous-uj3jx
    @Anonymous-uj3jx 2 роки тому +8

    Hello Striver! Thanks for all your videos. Can you please upload a video on the problem "Sort A Stack" which is in SDE sheet. It is really tough to understand😢

    • @atharvanigal
      @atharvanigal Рік тому +2

      yeah man babbar had taught it with recusion but i did'nt understand the whole recursion properly

  • @selvaragavan_10
    @selvaragavan_10 10 місяців тому +2

    Bro you're starting from zero and how does it checks the next greater element???

  • @gowthamarun43
    @gowthamarun43 3 роки тому +3

    we can try the same logic by traversing from the end also like normal array variant

  • @stormwalker1130
    @stormwalker1130 3 роки тому +10

    Watched your n queen and sudoku problem,the explanation was awesome.

  • @swastikkumarpal7795
    @swastikkumarpal7795 2 роки тому +2

    bhaiya there is something wrong in the for condition ...it should start iterating from backward

  • @onlygaming24-h7d
    @onlygaming24-h7d Рік тому +1

    i was at dp 55 i was suggested to watch largest rectangle in histogram and there i was suggested to watch first the next greater element so this is how i am here.
    Now i will watch this then i will again go to largest rectangle in histogram and then where i was originally exactly to DP 55

  • @Chhooso
    @Chhooso 7 місяців тому +1

    im dry running so times but still didnt understand how that code works under circular condition
    it will work without that condition and in coding ninjas too that condition is not mentioned ig
    idk y whenever i start from the end i just get it -1 after dry running and the rest is correct

    • @Chhooso
      @Chhooso 7 місяців тому

      my bad got it...never doubt striver

  • @omkarsk98
    @omkarsk98 Рік тому

    Excellently explained why removing the element wont affect the solution for previous elements

  • @franciskp9117
    @franciskp9117 7 місяців тому

    Bro In the first few minutes of the video you are iterating the array from right to left, but when the sudo code is shown, you start 'i' from 0 and go till 2n-1. Isn't this the other way around ? Like shouldn't 'i' start from 2n-1 and end at i >= 0. Correct me if I'm wrong.

  • @ashwanisingh1135
    @ashwanisingh1135 3 роки тому +2

    saw the title , went to solve the problem and then came back here to see the best approach

  • @protyaybanerjee5051
    @protyaybanerjee5051 Рік тому +2

    Concept - Monotonic Stack. Here we are using Monotonically Decreasing stack

  • @LifeGoing
    @LifeGoing 3 роки тому +5

    There is no doubt that your explanation is awesome.but it would much better if you will show code in code editor.

    • @takeUforward
      @takeUforward  3 роки тому +4

      Okay lets try that

    • @LifeGoing
      @LifeGoing 3 роки тому

      @@takeUforward hopefully it will be more understandable 😍

  • @AishwarysinghEC
    @AishwarysinghEC Рік тому +1

    why(i

  • @shrikantsharma8933
    @shrikantsharma8933 2 роки тому +3

    Hi, I really like your videos, just 1 question, which software or tool you are using to put these small animations on prerecorded videos?

  • @swaroopchakraborty3488
    @swaroopchakraborty3488 2 роки тому +4

    Great tutorial Striver. God bless you.
    I tried optimizing the solution for circular structure a little bit more if array lengths are short (n 0 && n != arr.length) {
    return null;
    }
    int[] nge = new int[1];
    if (arr.length > 0 && arr.length < 2) {
    nge[0] = -1;
    return nge;
    }
    if (arr.length == 2) {
    nge = new int[2];
    if (arr[0] < arr[1]) {
    nge[0] = arr[1];
    nge[1] = -1;
    } else {
    nge[0] = -1;
    nge[1] = arr[0];
    }
    return nge;
    }
    // The Stacking Algorithm will work only if there are more than 2 elements in
    // array. This is
    // done for reducing space and time complexity for arrays which are less than
    // n=2 in length or are relatively small.
    nge = new int[n];
    Stack st = new Stack();
    // Circular array implementation 2n-1
    for (int i = 0; i < 2 * n - 1; i++) { // n-1
    while (!st.empty() && st.firstElement()

  • @gaganeshmahajan7198
    @gaganeshmahajan7198 Рік тому +1

    Can someone please explain why he took the loop till 2n-1?? I didnt understand..Please help..

  • @bhaveshkumar6842
    @bhaveshkumar6842 2 роки тому +1

    Thank you, Striver!!! You're the best!!

  • @anubhavsingh8144
    @anubhavsingh8144 3 роки тому +3

    Great work bhaiya
    I have a request to make bhaiya
    Pls make a video on "Find K closest elements" Using Binary Search..
    Leetcode: 658

    • @chetanraghavv
      @chetanraghavv 2 роки тому +1

      class Solution {
      public:
      vector findClosestElements(vector& arr, int k, int x) {
      int n = arr.size();

      if(n == 1)
      return arr;
      vector res;
      int start = 0, end = n-1, mid=0;
      while(start =0 && end=0) //means end pointer is exhausted, select elements from start in this case
      {
      res.push_back(arr[start]);
      start--;
      k--;
      }
      while(k>0 && end

  • @surajsah3361
    @surajsah3361 Рік тому

    in explanation you iterate from index of last element and in code you are itterating from starting element?

  • @stith_pragya
    @stith_pragya Рік тому +1

    Thank You So Much Striver Brother.....🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @varun1017
    @varun1017 7 місяців тому

    16:40
    I think iteration should be done in reverse order. forward is not working for me.

  • @utkarshgupta3869
    @utkarshgupta3869 3 роки тому +3

    Hello bhaiya,
    I have one question... please reply...
    I am a B.Sc(c.s) Student.
    Please help me to know can I get a job(above 5 lpa) after my Graduation.
    I learnt enough C++ and completed DSA and going to start web development and also 3 star at codechef.
    I can learn anything for job after Graduation.
    Please help to me tell that can I get or I have to do MCA.

    • @Sarojkumar-yh9uy
      @Sarojkumar-yh9uy 2 роки тому +1

      Just start applying to relevant job openings

  • @samjackson4982
    @samjackson4982 Рік тому

    can anyone answer, why we are going through the array in reverse order? what is the intuition?

  • @vitaminprotein2217
    @vitaminprotein2217 2 роки тому

    leetcode 1019 cpp sol:(of linkedlist)
    vectorans;
    stackst;

    //convert the LL in ans(array/vector)
    while(head){
    ans.push_back(head->val);
    head=head->next;
    }
    //now it became a normal array q
    for(int i=ans.size()-1;i>=0;i--){
    while(!st.empty() && st.top()=0;i--){
    while(!st.empty() && st.top()

  • @ayeshasumaiya8280
    @ayeshasumaiya8280 2 роки тому +1

    Very clear and detailed explanation I thought my brain cannot understand the logic behind this simple problem but your explanation made it crystal clear

  • @mohithguptakorangi1766
    @mohithguptakorangi1766 3 роки тому +7

    ok, so you have written the code wrong?? cause i=2n-1 should be the initialized, I've been cracking my head

    • @takeUforward
      @takeUforward  3 роки тому +1

      Please watch the video completely… i%n has been used.. no need to initialize..

    • @mohithguptakorangi1766
      @mohithguptakorangi1766 3 роки тому +3

      @@takeUforward I meant (i=2n-1; i>=0;i--)
      the way you wrote in github code.....OR both are correct?

    • @takeUforward
      @takeUforward  3 роки тому +2

      Oops, my bad.. github is correct!

    • @mohithguptakorangi1766
      @mohithguptakorangi1766 3 роки тому +4

      @@takeUforward Ok cool....I watch your videos completely see?? so I'm getting better than you haha. Have a good day

    • @takeUforward
      @takeUforward  3 роки тому +3

      @@mohithguptakorangi1766 haha, actually while writing code, i need to explain, see in camera, hence concentration XD

  • @ayush_Bhagat129
    @ayush_Bhagat129 3 місяці тому +1

    class Solution {
    public:
    vector nextGreaterElements(vector& nums) {
    int n = nums.size();
    stack st;
    vector Nge(n, -1);

    for (int i = 2 * n - 1; i >= 0; i--) {
    while (!st.empty() && st.top()

  • @Rituresh
    @Rituresh 3 роки тому +1

    bhaiya aaj ya question smajh mai aa gaya aapki viddeo sai.you are doing good eork

  • @ronakslibrary8635
    @ronakslibrary8635 Рік тому

    Thanks sir for explaining this concept , the use of Stack is improvinzing the efficiency of solution by lot

  • @BRSanush
    @BRSanush 2 роки тому +1

    Wow what an explaination.
    Thank you striver.

  • @humble.660
    @humble.660 Рік тому

    CODE in Python:
    class Solution:
    def nextGreaterElements(self, nums: List[int]) -> List[int]:
    res = [-1] * len(nums)
    n = len(nums)
    stack = []

    for i in range(2 * len(nums) - 1, - 1, - 1):
    while stack and nums[i % n] >= stack[-1]:
    stack.pop()
    if stack:
    res[i % n] = stack[-1]
    stack.append(nums[i % n])
    return res

  • @JosepJeev
    @JosepJeev Рік тому +1

    Shdnt i be as I=2*n-1 instead of i=0

  • @igaming_
    @igaming_ Рік тому

    We have to make i%n for every i except for for loop
    Am I right guuys reply...

  • @suryapriya1953
    @suryapriya1953 9 місяців тому

    Bro please teach us with a small example with 11 elements . it ll be efficient to understand to beginners with 5 to 6 elements.

  • @MuhammadFahreza
    @MuhammadFahreza 2 місяці тому

    what is the time complexity on 12:16? Thanks!

  • @googlysahoo1397
    @googlysahoo1397 3 роки тому +1

    For the first variant, the size of the array will be n then why and how we will take 2n-1??
    Though for 2nd variant we are copying the elements(imaginary) we will assume the size to be 2n-1 but not in the first case.
    Could anyone explain the reason??

    • @takeUforward
      @takeUforward  3 роки тому

      In first case, we don’t have the circular array concept. If there does not exists on right, its -1

    • @googlysahoo1397
      @googlysahoo1397 3 роки тому +1

      My doubt is why to run the loop from 0 to 2n-1 where the size of the array is n?
      for(int i = 2n-1; i >= 0; i++) // this line

    • @ritishgupta2982
      @ritishgupta2982 3 роки тому

      @@googlysahoo1397 do i--

    • @gauravmutha2536
      @gauravmutha2536 2 роки тому

      Did you get your answer?

  • @doctordsa8669
    @doctordsa8669 6 місяців тому

    This is one of the best videos I have watched on the internet

  • @whatthecode7219
    @whatthecode7219 3 роки тому +1

    Solved this question 2 days back, nonetheless, enjoyed the explanation :)

  • @pryansh_
    @pryansh_ Рік тому +1

    you are the best on YT..

  • @aniketpandey1913
    @aniketpandey1913 Рік тому

    Hi Guys,
    problem : find next greater element to the right in array
    Solution: we use stack for solving this
    Doubt : some people prefer to store indices rather than the actual element in the stack
    can someone pls explain why the first approach is better than the other.
    One advantage i can think of is that in case of storing indices we save space

    • @DR-mq1le
      @DR-mq1le Рік тому

      doesnt matter since integer will anyways take the same space(as indices and elements both are int type) , if say the elements were some other bigger data type than int , then it would make sense storing indices , but then also negligible difference would be there

  • @AshishKumar-pq6pr
    @AshishKumar-pq6pr 3 роки тому +2

    Awesome lecture bhaiya

  • @sidarthroy815
    @sidarthroy815 2 роки тому

    so after i>n there will be empty iteration(with just pushing nd poping in stack) for rest half till it reaches 2n-1?

    • @amanbhadani8840
      @amanbhadani8840 2 роки тому

      Yes,basically for i>=n its just pushing and popping,but this step will ensure that if there is any element greater than last index element present on the left side,it will be already there in stack. And for i

  • @kamleshjoshi2949
    @kamleshjoshi2949 2 роки тому +2

    Waah jo doubt aya whi btadiya 😅 OP 🔥🔥

  • @MyPathUnveiledYT
    @MyPathUnveiledYT 7 місяців тому

    in circular array method i think answer should be like 10 12 -1 11 -1 not 10 12 --1 11 -1

  • @pankajkumarshukla9253
    @pankajkumarshukla9253 Рік тому

    Your teaching ability is awesome ,bro keep it up.

  • @111rhishishranjan2
    @111rhishishranjan2 Рік тому

    I didn't get that why you used circular array and made the solution difficuilt to understand . mean normal array also work well i guess.If anyone understood it , kindly explain me too ,
    //Here is my code
    #include
    using namespace std;
    vector nextGreaterElement(vector v){
    int n=v.size();
    vectorarr1(n,0) ;
    stacks;
    for(int i=n-1;i>=0;i--){
    //int currentprice=v[i];
    while(!s.empty() and s.top()

    • @srinathchembolu7691
      @srinathchembolu7691 Рік тому

      he explained a total of 2 questions. The circular array one is next greater element II on leetcode

  • @youtubeuserlovesyoutube2207
    @youtubeuserlovesyoutube2207 3 місяці тому

    striver bro
    the loop cond should be
    for (int i = (len * 2) - 1; i >= 0; i--)
    Isn't it>?

    • @sp_9467
      @sp_9467 2 місяці тому

      Yes you are right

  • @umangjaiswal7448
    @umangjaiswal7448 Рік тому

    for circular , can we use upper_bound to solve problem ??

    • @gauravmehra8189
      @gauravmehra8189 Рік тому

      did you find the answer to your question? can we use upper_bound for circular?

  • @amandubey5287
    @amandubey5287 Рік тому

    This is just amazing and very well explained. Thanks

  • @sasanknvs5603
    @sasanknvs5603 Рік тому +3

    I think the for loop is wrong. Since we are iterating from right, we should start the for loop from i=2n-1. It was correctly implemented on the C++/Java code links in the description

  • @shubhamgupta9778
    @shubhamgupta9778 3 роки тому

    Thank u bro.... Your video always give us very good concept.....
    Please make a session on josephus problem. This problem is very easy to understand but hard to implement.

  • @nishantjarang7302
    @nishantjarang7302 2 роки тому

    can you make a video,how to reverse a linkedlist of group of given size

  • @gautamnegi6868
    @gautamnegi6868 3 роки тому

    In while loop its showing stackempty error and the flow is not going to the if statement.please rply

    • @takeUforward
      @takeUforward  3 роки тому +1

      The code in the description has been tested , please refer it :)

  • @ApnaVlogs-tj7do
    @ApnaVlogs-tj7do Рік тому

    Wonderful explanation bhaiya

  • @rohith8269
    @rohith8269 Рік тому

    Greeeaaaaaaattt explanation!!!! Thankyou so much

  • @shubhambhatt2704
    @shubhambhatt2704 Рік тому

    How do you even come up with these solutions?

  • @ritesh1211
    @ritesh1211 Рік тому

    int n = arr.size();
    vectorans(n,-1);
    stackstk; //dec to find next greater
    for(int i=0;iarr[stk.top()]){
    int poped = stk.top();
    ans[poped]=arr[i%n];
    stk.pop();
    }
    stk.push(i%n); //pushing indexs
    }


    return ans;

  • @manusharma1516
    @manusharma1516 8 місяців тому

    how come i is starting from 0. I didn't get it.

  • @abinvarkey2331
    @abinvarkey2331 Рік тому

    best video on the topic i could find!

  • @sivaganesh4489
    @sivaganesh4489 2 роки тому +1

    initially i worried about the run time of the video. after watching the video, i enjoyed every second of it. really great explanation dude.

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      for first variant why we running for 2*n-1 ... it should be done only for circular onces !!

    • @amanbhadani8840
      @amanbhadani8840 2 роки тому

      @@PIYUSH-lz1zq yes

  • @rakib_8feb
    @rakib_8feb Рік тому

    13:10 Circular Array

  • @amanbhadani8840
    @amanbhadani8840 2 роки тому

    Amazing explanation !!

  • @securelyinsaycure
    @securelyinsaycure 6 місяців тому

    Smooth like butter 🧈

  • @KoushikVarma-h1b
    @KoushikVarma-h1b 2 роки тому

    Next greater element for 7 is 10 not -1. 3:47

  • @dakanksha1806
    @dakanksha1806 Рік тому

    Great explaination. Although won't the Time complexity be O(n^2) as for loop is running for n and while loop at the worst case will run for n elements as well. Thus, n*n = n^2. Someone kindly explain if I m thinking in wrong direction.

    • @sagniksaha4179
      @sagniksaha4179 Рік тому

      Same question, did you got any answer for this . this was the reason I wasn't able to solve this problem as the required complexity is O(n)

  • @SatyamKumar-bw4vi
    @SatyamKumar-bw4vi 2 роки тому +1

    Hare Krishna!

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      for first variant why we running for 2*n-1 ... it should be done only for circular onces !!

    • @gauravmutha2536
      @gauravmutha2536 2 роки тому

      @@PIYUSH-lz1zq Did you get the answer,I too am facing same problem.

  • @rgvhere
    @rgvhere 7 днів тому

    u watch showing time 3:23 bro

  • @anurondas3853
    @anurondas3853 Рік тому

    Man... Guys stop paying thousand of rupees for learning to code!! Striver over here does it better than any and all of them! Really great video.😆😁

  • @ShivaShiva-py9zt
    @ShivaShiva-py9zt 2 роки тому

    Bhaiya shuruwat s kaise declare krte h stack, vector sb woh sb bhi padhaye toh hm jaise bccho k liye useful hoga

    • @PIYUSH-lz1zq
      @PIYUSH-lz1zq 2 роки тому

      for first variant why we running for 2*n-1 ... it should be done only for circular onces !!

  • @raghavendrasoni6712
    @raghavendrasoni6712 2 роки тому

    great explanation man!

  • @leepakshiyadav1643
    @leepakshiyadav1643 2 роки тому

    Excellent explanation :)

  • @shanmukhavarma3361
    @shanmukhavarma3361 3 роки тому

    i could able to find dp for this

  • @LaxmiTeja-c2f
    @LaxmiTeja-c2f Рік тому

    You are a saviour!!

  • @yshanroy2264
    @yshanroy2264 3 роки тому +1

    Bro u live in sonapur na??

  • @azraazra8273
    @azraazra8273 3 роки тому

    Sir please put this in a seperate palylist

    • @takeUforward
      @takeUforward  3 роки тому

      Already done, check stack queue playlist

  • @abd6406
    @abd6406 Рік тому

    "for' loop will be on reverse

  • @bhagirathmakwana9112
    @bhagirathmakwana9112 Рік тому +1

    my brother u are great

  • @kainathussain6973
    @kainathussain6973 2 роки тому

    god level explaination🤩😍

  • @dpxy1599
    @dpxy1599 Рік тому

    nicely explained

  • @Shubham-zl1zb
    @Shubham-zl1zb 5 місяців тому

    Thank you

  • @adarshrai9516
    @adarshrai9516 3 роки тому +1

    Thanks bro ❤️