Print the elements from the given array, in decreasing order.
Ex. you are given an arr like [4,5,1,2,3], so output should be -
<BlankLine>
5, 4
<BlankLine>
<BlankLine>
3, 2, 1
Explanation : first we get 4, & we know that bigger element exists, so can't print it & blank line is printed for this element.
Next we get 5 & we know that this is the largest element in array not yet printed but we also have some elements before it not yet printed on console. So we need to check if the elements received till 5 can be printed on console without having any bigger element in between from the other array elements. And we see here that both 4 & 5 don't have any other element from the array which can come in between, so we can safely print these 2 elements in decreasing order on the console, like 5, 4
Next 1 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 2 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 3 comes, we see that no other bigger element remaing now.
So we can check 1,2,3 also like we did for 4 & 5, if no remaining can come in between.
So we print 3, 2, 1
Below is one kind of solution, not efficient one & you can provide the better solution in comment section
Ex. you are given an arr like [4,5,1,2,3], so output should be -
<BlankLine>
5, 4
<BlankLine>
<BlankLine>
3, 2, 1
Explanation : first we get 4, & we know that bigger element exists, so can't print it & blank line is printed for this element.
Next we get 5 & we know that this is the largest element in array not yet printed but we also have some elements before it not yet printed on console. So we need to check if the elements received till 5 can be printed on console without having any bigger element in between from the other array elements. And we see here that both 4 & 5 don't have any other element from the array which can come in between, so we can safely print these 2 elements in decreasing order on the console, like 5, 4
Next 1 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 2 comes, we can't print it now, as other big elements still pending, so <BlankLine>
Next 3 comes, we see that no other bigger element remaing now.
So we can check 1,2,3 also like we did for 4 & 5, if no remaining can come in between.
So we print 3, 2, 1
Below is one kind of solution, not efficient one & you can provide the better solution in comment section