Decent Arrays

#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

program
I am getting WA in testcase 6 :sweat_smile:

1 Like

Sorry, it’s my bad. Now i am able to figure it out :grinning_face_with_smiling_eyes:

code
#Python 3.8

N = int(input())
A = input().split()

def ascend(lis):
	index = 0
	outdex = len(lis)
	while index < outdex-1:
		if lis[index] > lis[index+1]:
			return False
		index += 1
	return True

if ascend(A):
	print("Yes")
else:
	print("No")

why the code shows wrong answer on 5th case?

@Marzuq01 This is happening because you are comparing the numbers as strings instead of integers.

In Python:

>>> 9 > 10
False
>>> '9' > '10'
True

Change your second line from A = input().split() to A = map(int, input().split()).