Siddharth and Permutations

i understood the question . please tell me how it is a graph problem . also please give any hints. But please tell how to think it is a graph problem

I`ll just let you know about why it a graph questionnn
Please wait for a while

1 Like

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.

1 Like

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.

1 Like

do i have to use segment tree or simply topological sort se kam chal jayega, please help.

@chhavibansal
do i have to use segment tree or simply topological sort se kam chal jayega, please help.

@RAHUL simply use topoplogical sort ,it will work.

1 Like

i have written the code but it fails on submission . however custom test are passing.
please provide your code for reference.
@rishabhmahajan546
@chhavibansal

@apaarkamal please help

@RAHUL hope you get the logic of code ,I am closing this doubt fell free to reopen it.

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.