Repository navigation
Expand file tree
/
Copy pathday25.java
More file actions
87 lines (72 loc) · 1.99 KB
/
Copy pathday25.java
File metadata and controls
87 lines (72 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
* Enter your code here. Read input from STDIN. Print your output to STDOUT.
* Your class should be named CandidateCode.
For this challenge, you need to take number of elements as input on one line and array elements as an input on another line. You need to tell whether the numbers present in the array are consecutive or not.
Input Format
In this challenge, you will take number of elements as input on one line and array elements which are space separated as input on another line.
Constraints
1 < N < 10^5
1 < A[i] < 10^5
Output Format
If the array elements are consecutive, print 'True' else print 'False' to the stdout.
Sample TestCase 1
Input
6
11 22 33 44 55 66
Output
False
*/
import java.io.*;
import java.util.*;
public class CandidateCode {
public static void main(String args[] ) throws Exception {
//Write code here
Scanner sc = new Scanner(System.in);
int arr[],i=0,j,l,k=0;
l = sc.nextInt();
arr = new int[l];
if (l>1 && l<=100000)
{
for(i=0;i<l;i++)
{
arr[i] = sc.nextInt();
}
j=arr[0];
if(arr[0]>arr[1])
{
for(i=1;i<l;i++)
{
if(arr[i] == (j-1) )
{
j++;
continue;
}
else
{
System.out.print("False");
break;
}
}
}
else if(arr[0]<arr[1])
{
j = 0;
for(k=1;k<l;k++)
{
if(arr[k] == arr[j]+1 )
{
j++;
continue;
}
else
{
System.out.print("False");
break;
}
}
}
if(i==l && k==l)
System.out.print("True");
}
}
}