Efficient one algorithm of these two algorithms

Both of these algorithms are giving same output but the first one takes nearly double time (>.67) compared to second one (.36). How is this possible? Can you tell me the time complexity of both algorithms? If they're the same, why is the time different?

1st algorithm:

 for (int i =0 ;i<n;i++){
        cin>>p[i];
        if(i>0){
            if(p[i-1]>p[i]){
                cout<<p[i]<<" ";
            }
            else{
                cout<<"-1"<<" ";
            }
        }
    }

2nd algorithm:

for (int i =0 ;i<n;i++){
        cin>>p[i];
}
for (int i =0 ; i&lt;n-1;i++){
   if(p[i]&gt;p[i+1]){
            cout&lt;&lt;p[i]&lt;&lt;" ";
        }
        else{
            cout&lt;&lt;"-1"&lt;&lt;" ";
        } 
}


#c++ #algorithm

2 Likes2.85 GEEK