Help me in solving DPOLY problem

My issue

This is my code, the outputs are correct but on submitting it gives wrong answer at task 2. Can someone please point out the error.

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
    int tests; cin >> tests;
    while( tests > 0 ){
        tests = tests - 1;
        int num; cin >> num;
        int arr[num]; int l=0;
        for (int i=0; i<num; i++){
            cin >> arr[i];
        }
        for (int i=1;i<num; i++){
            if (arr[i]>arr[i-1]){
                l=i;
            }
            else{
                l=i-1;
            }
        }
        cout << l << endl;
    }
}

Problem Link: Degree of Polynomial Practice Coding Problem - CodeChef

@kirti21ag
here plzz refer my c++ code for better understanding of the logic

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	    }
	    for(int i=n-1;i>=0;i--)
	    {
	       if(a[i]!=0)
	       {
	           cout<<i<<endl;
	           break;
	       }
	    }
	}

}