Doubt in the question

if an array is 1 23 44 13 89 then the output will be
23 44 44 89 89 89 89 89 right? till it reaches the last index after one round right?

@aryaman.kumar26
it will be
23 44 89 89 -1

okay mtlb after comparing 13 and 89 we will compare 89 and 1 and then we won’t compare 89 with 23 right?

@aryaman.kumar26 we just have to compare till last start from that index.
for 89 its already the last so -1

okay so if we don’t find bigger element than 89 as given int he example then the answer should 23 44 44 89 -1 as there is no bigger number than 89 right?

@aryaman.kumar26
23 44 89 89 -1 is the ans not 23 44 44 89 -1

well the answer should be 23 44 -1 89 -1 right?

@aryaman.kumar26 for 44 greater is 89 so why -1

so its a sliding window concept right?

@aryaman.kumar26 it can be done using stack

sir there is 13 in between 44 and 89

better can be done using vector. but it as vector doubles its space therefore not good for large number of elements right?

@aryaman.kumar26 you have to find next greater element till the end if found
Ex 3 1 2 1 4
So ans
4 2 4 4 -1