CARVANS in DSA Learning Series - Contest 1

What’s wrong in my approach for

https://www.codechef.com/viewsolution/30882940

Try This:

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

int main() {
int t;
cin >> t;
while(t!=0){
t–;
int n,c=0;
cin >> n;
int arr[n];
for(int i=0;i<n;i++){
cin >> arr[i];
}
for(int i=0;i<n-1;i++){
if(arr[i]<arr[i+1]){
arr[i+1] = arr[i];
}
else{
c++;
}
}
cout << c+1 << endl;
}
return 0;
}

Thanks broo it’s giving correct answer
I got confused with question as they asked number of cars, but incase they asked maximum number of car , Is my solution correct…

Repost your soln as it is not visible.

#include <bits/stdc++.h>
using namespace std;
#define endl ‘\n’
#define ll long long
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
vectorarr(n),dp(n,1);
ll ans=1;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
dp[0]=1;
for(int i=1;i<n;++i)
{
for(int j=i-1;j>=0;–j)
{
if(arr[j]>arr[i])
{
dp[i]=max(dp[i],dp[j]+1);
}
}
ans=max(ans,dp[i]);
}
cout<<ans<<endl;
}

return 0;

}