Decent Arrays

package javaapplication29;

import java.util.Scanner;

public class solution {

    public static void main(String[] args) {
       Scanner sc= new Scanner (System.in);
       int n=sc.nextInt();
       boolean x=true;
       int N[]= new int[n];
       int i=0;
       while(i<n){
           N[i]=sc.nextInt();
           i++;
       }
       i=0;
       while(i<n-1){
           if(N[i]<N[i+1]){
               x=true;
           }
           else{
               x=false;
               break;
           }
           i++;
       }
       if(x==true) System.out.println("Yes");
       else if(x==false)  System.out.println("No");
    }
    
}

fault of this code?

ignore 1st line but yet in 4th test case it shows wrong ans
why?

updated code but still same problem

import java.util.Scanner;

public class solution {

    public static void main(String[] args) {
       Scanner sc= new Scanner (System.in);
       int n=sc.nextInt();
       boolean x=true;
       int N[]= new int[n];
       int i=0;
       while(i<n){
           N[i]=sc.nextInt();
           i++;
       }
       i=0;
       while(i<n-1){
           if(N[i]<N[i+1]){
               x=true;
           }
           else if(N[i+1]>N[i]){
           x=true;
           }
           else{
               x=false;
               break;
           }
           i++;
       }
       if(x==true) System.out.println("Yes");
       else if(x==false)  System.out.println("No");
    }
    
}

@ph3nixsabit
The problem is when N[i] == N[i+1], your code will fail.

What’s the problem in my code???

#include<stdio.h>
#include<math.h>
#include<string.h>
/*
Author: Md Alhaz Mondal.
Institute: Faridpur Polytechnic Institute.
Faridpur,Dhaka,Bangladesh.
*/
int main()
{
int T,i=0,j=0,n,s=0;
scanf(“%d”,&T);
if((0<T)&&(T<100))
{
int ar[T];
while(i<T)
{
scanf(“%d”,&n);
ar[i]=n;
i++;
}
while(j<T)
{
if((ar[j]>ar[j+1])||(ar[j]==ar[j+1]))
{
s=1;
}
j++;
}
if(s==0)
{
printf(“Yes”);
}
else
{
printf(“No”);
}
}
return 0;
}

@hredhayxz, follow this to mark up your codes correctly. I will look at this when I get your notification.

#include<stdio.h>
int main()
{
int n,i;
scanf(“%d”,&n);
int a[n];
for(i=0;i<n;i++){
scanf(“%d”,&a[i]);
}

for(i=0;i<n-1;i++){
    if(a[i]>a[i+1]){
        printf("No\n");
        return 0;
    }
}
    printf("Yes\n");

return 0;

}
accepted in your perspective

Please don’t share accepted codes in the community. You should point out the mistakes so that one can figure out the solution on their own.

And please format your codes properly before sharing them in the community. You can use this post as a reference.

ohh ok … sorry. bro.

Not to worry, I just pointing out the community rules since you seemed to be new here.
happy coding!!!

The Problem is Simple. You are taking a list of strings as input but trying to compare them as numbers.
Even in Python strings can also be compared the same way as numbers, it doesn’t mean the comparison between numbers and their equivalent string expressions will be the same.

Simply, even your code runs successfully, your submission won’t be accepted. You have to convert the strings of the list to numbers first before comparing them.

And again, Please remove the link of the accepted solution you have posted here. Although not punishable, it is usually discouraged by the moderators of Toph.

This is another poorly defined problem. It should ask to check for either strictly ascending or non-descending values. “Ascending” can mean either of these two things. Or perhaps it is asking for something else? Should [1,1,1,1,1,1,1,1] be considered “ascending”?

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n, i;
cin>>n;
if(n==1) cout<<“Yes”<<endl;
else
{
char a[n];
for(i=0; i<n;i++)
cin>>a[i];
for(i=1; i<n; i++)
{

    if(a[i-1]>a[i])
    {
        cout<<"No"<<endl;
        break;
    }
}
if(i==n) cout<<"Yes"<<endl;
}

}

where is the problem in my code?

#include<stdio.h>

int main()
{
    int i,key=0,n;
    scanf("%d",&n);
    int list[n];
    for(i=0;i<n;i++){
        scanf("%d",&list[i]);
    }
    for(i=0;i<n-1;i++){
        if(list[i]>=list[i+1]){
            key = 1;
            break;
        }
    }
    if(key==0){
        printf("Yes");
    }
    else{
        printf("No");
    }
    return 0;
}

What is wrong with my code???

Scanner inpu=new Scanner(System.in);
        int N;
        int count=0;
        N=inpu.nextInt();
        int array[]=new int[N];
        for (int i = 0; i <N; i++) {
            array[i]=inpu.nextInt();
        }
        for (int i = 0; i <N-1; i++) {
               if(array[i]<=array[i+1]){
                   count++;
               }
        }
        if(count==N-1){
            System.out.print("yes");
        }else{
            System.out.print("No");
        }

whats the prblm in my code ?

It seems that you have solved the problem yourself.

whats the problem in this code ?

You wrote yes instead of Yes

What about 1? What if the line is 1…how do i check if this is asscending or not?

#include<iostream>
using namespace std;
main()
{
  int i,n;
  cin>>n;
  int a [n];
  for(i=1;i<n;i++)
  {
    if(a[i]>a[i-1])
    {
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

What is the problem in my code?
I get wa in test case 4