Help me in solving ASMBLY problem

My issue

My code

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	long long int n,i=0,j=0,a[100000],count=0;
	cin>>n;
	for(i=0;i<n;i++){
	    cin>>a[i];
	}
	for(i=0;i<n;i++){
	    j=i+1;
	        if(a[i]>a[j]){
	        count++;
	        break;
	        }
	        else{
	        count++;
	        }
	    
	}
	cout<<count;
	return 0;
}

Problem Link: CodeChef: Practical coding for everyone

@smriti_0109 just try to check if the next number is greater than current number .
I used this logic in my loop. as soon as I passed one condition , I updated the value of the variable in the condition.
I have pasted my code below .

hope this helps !!

include
using namespace std;

int main() {
// your code goes here
int n;int count=0;int max=0;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]>max)
{
count++;
max=a[i];
}

}
cout<<count<<endl;
return 0;

}

1 Like