My issue
Some of the test cases are not satisfied
could help me to rectify the program
My code
#include <iostream>
using namespace std;
int main()
{
long long int n,c=1;
cin>>n;
long long int h[n];
for(int i=0;i<n;i++)
cin>>h[i];
for(int i=1;i<n;i++)
{
if(h[i]>h[i-1])
c++;
else
continue;
}
cout<<c;
return 0;
}
Problem Link: CodeChef: Practical coding for everyone
The problem with this code can be illustrated by the testcase :-
5
1 2 5 3 4
Here, your code will give output 4 (because it will count 4 also as it is appearing after 3); but correct output will be 3.
/* Efficient solution */
include
using namespace std;
int main(){
// input variables
int n;
long height;
// taking input
cin >> n;
// helper variable
long max = 0;
// output variable
int cnt = 0;
// logic
for(int i=0; i<n; i++){
cin >> height;
if (height > max) {
max = height;
cnt++;
}
}
cout << cnt << endl;
return 0;
}
@codestar05
you’re most welcome