Game of Two Stacks | HackerRank

i was getting TLE for the last three test cases(on hackerrank) for this submision

so what i did was to use the two pointer theorem to iterate over the array thus decreasing its time complexity

but i am getting a TLE on the first test case itself please help me out to solve this problem using the two pointer algorithm

p>=1 in while loop.

i didnt get it bro can u provide more hint