WA in "Another Birthday Present" (SHUFFLE) Lunchtime April 2020

https://www.codechef.com/viewsolution/32418330
Can anyone tell me whats wrong with my code ?

take this test case
1
6 2
5 6 3 4 1 2

answer should be yes

https://www.codechef.com/viewsolution/33088205

it is showing TLE!!
please help!!

What do you think your complexity is?

@adi99_123
In Worst case complexity is O(N^2) that’s why giving tle.