import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long c = 0;
int i = 1;
int f = 0;
int y = 0;
while(i<=n){
long x = sc.nextInt();
if(f == 0 && x - c >= 0){
f = 1;
y++;
}
if(f == 0 && x - c < 0){
f = 1;
y++;
}
c = x;
i++;
}
if(y <= 2){
System.out.println(“true”);
}
else{
System.out.println(“false”);
}
}
}
here is my code but still got 5 testcases failed could anyone help
Increasing Decreasing Sequence
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int c = 10000000;
int y = 0;
while (n > 0) {
int x = sc.nextInt();
if (x >= c) {
c = x;
n--;
}
c = x;
n--;
}
int f = 0;
while (n > 0) {
int x = sc.nextInt();
if (x <= c) {
f = 1;
break;
}
c = x;
n--;
}
if (f == 0 && n == 0)
System.out.println("true");
else {
System.out.println("false");
}
}
@ravimaurya096_47edb35d740b0342 Bro I have corrected your code please check it.
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int c = 10000000;
int y = 0;
while (n > 0) {
int x = sc.nextInt();
if (x >= c) {
c = x;
n–;
break;
}
c = x;
n–;
}
int f = 0;
while (n > 0) {
int x = sc.nextInt();
if (x <= c) {
f = 1;
break;
}
c = x;
n–;
}
if (f == 0 && n == 0)
System.out.println(“true”);
else {
System.out.println(“false”);
}
}
}
@ravimaurya096_47edb35d740b0342 Sorry bro I just missed a ‘break’ keyword in the code. While correcting it. The correct code is given above.
Thank you so much brother for help