Yours also fails the testcase:
1
10 2
-1 -1 -1 -1 -1 2 -1 -1 -1 2
Edit:
You also have a lot of compiler warnings which you should verify aren’t causing a problem:
Compiler warnings
rashu1999-TRIP2.cpp:50:28: warning: using the result of an assignment as a condition without parentheses [-Wparentheses]
else if(no = -1 && arr[1] == -1)
~~~^~~~~~~~~~~~~~~~~~~~
rashu1999-TRIP2.cpp:50:28: note: place parentheses around the assignment to silence this warning
else if(no = -1 && arr[1] == -1)
^
( )
rashu1999-TRIP2.cpp:50:28: note: use '==' to turn this assignment into an equality comparison
else if(no = -1 && arr[1] == -1)
^
==
rashu1999-TRIP2.cpp:101:35: warning: '&&' within '||' [-Wlogical-op-parentheses]
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
~~~~~~~^~~~~~~~~ ~~
rashu1999-TRIP2.cpp:101:35: note: place parentheses around the '&&' expression to silence this warning
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
^
( )
rashu1999-TRIP2.cpp:101:55: warning: '&&' within '||' [-Wlogical-op-parentheses]
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
~~ ~~~~~~~^~~~~~
rashu1999-TRIP2.cpp:101:55: note: place parentheses around the '&&' expression to silence this warning
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
^
( )
rashu1999-TRIP2.cpp:101:69: warning: '&&' within '||' [-Wlogical-op-parentheses]
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
~~ ~~~~^~~~~~~~~
rashu1999-TRIP2.cpp:101:69: note: place parentheses around the '&&' expression to silence this warning
if(l == 1 && r == 1 || l == 1 && r>2 || l>2 && r == 1)
^
( )
rashu1999-TRIP2.cpp:104:40: warning: '&&' within '||' [-Wlogical-op-parentheses]
else if(l == 2 && r == 1 || l==1 && r==2)
~~~~~~~^~~~~~~~~ ~~
rashu1999-TRIP2.cpp:104:40: note: place parentheses around the '&&' expression to silence this warning
else if(l == 2 && r == 1 || l==1 && r==2)
^
( )
rashu1999-TRIP2.cpp:104:58: warning: '&&' within '||' [-Wlogical-op-parentheses]
else if(l == 2 && r == 1 || l==1 && r==2)
~~ ~~~~~^~~~~~~
rashu1999-TRIP2.cpp:104:58: note: place parentheses around the '&&' expression to silence this warning
else if(l == 2 && r == 1 || l==1 && r==2)