We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Two points to bear in mind while solving this problem:
A person can bribe the one who is sitting just in front of him. The opposite is not possible.
A person can bribe atmost 2 different persons.
Keeping this in mind, let's have a look at testcase-1.
First case:
Currentposition:51237864Initialposition:12345678
In the first test, the person-5 has occupied 1st seat.
That means he has to bribe 4 persons in front of him to reach on the 1st seat
So he violated the second rule here. So that answer is "Too chaotic" without further speculation.
Second case:
Currentposition:12537864Initialposition:12345678
So how did person-4 occupy at position 8?
As per the rules, it's not possible for person-4 to bribe persons who are sitting behind him.
Instead person 5, 6, 7 & 8 bribed person-4 as he is sitting infront of them.
Here is the trasition from initial position to the current position.
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
Two points to bear in mind while solving this problem:
Keeping this in mind, let's have a look at testcase-1.
First case:
In the first test, the person-5 has occupied 1st seat. That means he has to bribe 4 persons in front of him to reach on the 1st seat So he violated the second rule here. So that answer is "Too chaotic" without further speculation.
Second case:
So how did person-4 occupy at position 8? As per the rules, it's not possible for person-4 to bribe persons who are sitting behind him. Instead person 5, 6, 7 & 8 bribed person-4 as he is sitting infront of them. Here is the trasition from initial position to the current position.
Obviously no person violated the second rule here. Hence the output is minimum number of swaps 7.