**Here is the Problem Link**

Soldiers And Cards

My Submission link is My Submission

Please Provide me a Hint. I am getting TLE on Test Case 29. I am applying Brute Force Algorithm.

Help Required.

Thanks!

**Here is the Problem Link**

Soldiers And Cards

My Submission link is My Submission

Please Provide me a Hint. I am getting TLE on Test Case 29. I am applying Brute Force Algorithm.

Help Required.

Thanks!

Note: In this case(i.e Test case 29) , both of the players stack reach to a situation from where *Repetition of states starts* i.e after few swaps the stacks become same(as some previous state) but not equal to initial situation as given in Input. so your equate() function always returns 0.and hence TLE.

- Note you can keep a counter and assign it a upper bound and now if the number of iterations goes beyond upper bound value print -1.

Hope it helps.