-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDay17_prob2.java
More file actions
65 lines (52 loc) · 1.6 KB
/
Day17_prob2.java
File metadata and controls
65 lines (52 loc) · 1.6 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
/*
Consider Aman is visiting Nehru Zoo. She has seen there are N elephants standing in a row. She wants to remove the elephants having the same height standing in consecutive.Write a program for Aman so that she can get the desired sequence of elephants.
Input Format
The first line will be containing one Integer representing a number of elephants N.
The second line will contain N integers representing the heights of the elephants.
Constraints
N>2 && N<30
Output Format
The desired sequence of elephants after removing elephants having the same height standing in consecutive.
Sample Input 0
12
4 7 9 9 8 5 7 7 6 5 5 5
Sample Output 0
4 7 9 8 5 7 6 5
Sample Input 1
1
Sample Output 1
Invalid Input
*/
// kirtan jain
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
Scanner sc = new Scanner(System.in);
int n = sc.nextInt(), input, m=0;
if(n<=2 || n>=30){
System.out.println("Invalid Input");
}
else{
int a[]= new int[n];
for(int i=0;i<n;i++){
input=sc.nextInt();
if(i==0){
a[m]=input;
m++;
}
else if(a[m-1] != input){
a[m]=input;
m++;
}
}
for(int i=0;i<m;i++){
System.out.print(a[i]+ " ");
}
}
}
}