-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaxNumWithoutRepeatation.java
75 lines (68 loc) · 1.99 KB
/
MaxNumWithoutRepeatation.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
// given sequence is 'IDIDI' then output should be '132546'
class solution{
private static String getSequence(String arr){
int n = arr.length();
int[] res = new int[n+1];
int low = 1, high = n+1;
for(int i=0;i<n;i++){
if(arr.charAt(i)=='I'){
res[i] = low++;
}else{
res[i] = high--;
}
}
res[n] = low;
StringBuilder sb = new StringBuilder();
for(int i=0;i<=n;i++){
sb.append(res[i]);
}
return sb.toString();
}
private static String getInput(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String input = null;
try{
input = br.readLine();
}catch(Exception e){
e.printStackTrace();
}
return input;
}
public static void main(String[] args){
String input = getInput();
System.out.println(getSequence(input));
}
}
//class solution{
// private static String getSequence(String arr){
// String result = "";
// int max = 0;
// for( char c : arr.toCharArray() ){
// if(c=='I'){
// result += Integer.toString(max);
// max++;
// }
// else{
// result += Integer.toString(max);
// max=(max+3)%10;
// }
// }
// return result;
// }
// priavte static String getInput(){
// BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
// try{
// return br.readLine();
// }
// catch(Exception e){
// return null;
// }
//}
//public class MaxNumWithoutRepeatation {
// String intList = getInput();
// String answer = getSequence(intList);
// System.out.println(answer);
//}
//}