-
Notifications
You must be signed in to change notification settings - Fork 101
/
NumberChecker.java
73 lines (66 loc) · 2.06 KB
/
NumberChecker.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
/**
*problem statement-
---------------------------------
Given an integer array as input, find out the integers which contains the digits 1,2,3 numbers in its formation . The order of 1,2,3 need
not be sequential.
In case multiple numbers qualifies the condition, The outcome should be ordered based on numeric value (lesser number first followed
by greater number and so on..) and separated by comma.
In case no number qualifies the conditions, it should return -1.
Example:
Input :
1456
345671
43218
123
Output: 123,43218
Explanation: In the above example, as there are 2 numbers(43218,123) which qualifies the condition, we need to sort the output in
ascending order seperated by comma.
*
*/
package com.javaaid.ip.goldman_sachs;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Scanner;
/**
* @author Kanahaiya Gupta
*
*/
public class NumberChecker {
static String findQualifiedNumbers(int[] numberArray) {
Arrays.sort(numberArray);
String num = "", res = "";
for (int i : numberArray) {
num = i + "";
if (num.indexOf("1") != -1 && num.indexOf("2") != -1 && num.indexOf("3") != -1) {
res += i + ",";
}
}
return res.equals("") ? "-1" : res.substring(0, res.length() - 1);
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(System.in);
final String fileName = System.getenv("OUTPUT_PATH");
BufferedWriter bw = null;
if (fileName != null) {
bw = new BufferedWriter(new FileWriter(fileName));
} else {