Sample Test case states that it is not possible to construct 1 good permutation with N=4.
But, I think it can be possible like this:- 3 2 4 1. Here, only 1 good permutation is possible with L=1, R=4. Why sample test case states that it is not possible?
Considering your chosen array i.e. [3, 2, 4, 1]
.
One of the good sub-segment is where L = 1
, and R = 4
, i.e. [3, 2, 4, 1]
.
There can be one more good sub-segment where L = 4
and R = 4
, i.e. [1]
.
Therefore, there are more than 1
good sub-segments possible for this particular case, hence answer is -1
.