Please help i don’t know how to solve it. Any solution is also not available can you provide a valid solution
Not able to understand how to solve this problem
When we analyse the question, we are certain to use topological sort. The way we came to this conclusion of using a graph is we see a dependency of 1 element on the other, basically, if we analyze the output for the given input we are trying to find the next greater element, marking the present element when pj > pi ( a thought of using a dfs strikes our mind)
We observe that the nodes (numbers) are related to one another, in a way a number will be marked observed if it is greater than the present number. Use graph when u see dependency of task on one another.
Just a suggestion from my experience:
You might think of using a graph where the series is from 1 to n like we generally denote vertices in sequential order. Given that u have thoroughly thought of using a array and u are failing to build some LOGIC.
SO basically dependency of items, connected components, ordering based on some relationship can get you to think of using a GRAPH.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.