Hi my code in java For the problem birthday candle is -
http://www.codechef.com/problems/CANDLE/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Main{
public static void main(String args[]) throws NumberFormatException,
IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
int testCases = Integer.parseInt(in.readLine());
while (testCases > 0) {
String[] stringArr = in.readLine().split(" ");
List<Integer> myList = new ArrayList<Integer>();
for (String str : stringArr) {
myList.add(Integer.parseInt(str.trim()));
}
int min = Collections.min(myList);
int minIndx = myList.indexOf(min);
if (minIndx > 0 && min == 0) {
out.println(minIndx);
} else if (min == 0 && minIndx == 0) {
List<Integer> indexList = myList;
indexList.remove(0);
int secndMin = Collections.min(indexList);
int secndMinIndex = indexList.indexOf(secndMin);
if (secndMin == 0) {
out.println(secndMinIndex + 1);
} else {
out.println(secndMinIndex + 1 + "0");
}
} else if (min > 0) {
ArrayList<Integer> indexList = new ArrayList<Integer>();
for (int ind = 0; ind < myList.size(); ind++) {
if (min == myList.get(ind))
indexList.add(ind);
}
int minNonZeroIndex = Collections.min(indexList);
int minNonZeroVal = myList.get(minNonZeroIndex);
if (minNonZeroIndex != 0) {
String str = minNonZeroIndex + "";
for (int cntr = 1; cntr <= minNonZeroVal; cntr++) {
str = str + minNonZeroIndex;
}
out.println(str);
} else {
List<Integer> tmpList = myList;
tmpList.remove(0);
int secndMin = Collections.min(tmpList);
int secndMinIndex = tmpList.indexOf(secndMin);
if (minNonZeroVal >= secndMin) {
String str = (secndMinIndex+1) + "";
for (int cntr = 1; cntr <= secndMin; cntr++) {
str = str + (secndMinIndex+1);
}
out.println(str);
} else {
String str = (secndMinIndex+1) + "";
for (int cntr = 0; cntr <= minNonZeroVal; cntr++) {
str = str + "0";
}
out.println(str);
}
}
}
testCases--;
}
out.flush();
}
}
After submission it is saying wrong answer and i am not able to find out any test case that fails…
Plz help