My code for 2nd problem in Kickstart2020 is showing runtime error even on testing. I am unable to find why this is happening.
I have tested here Online Compiler and IDE - GeeksforGeeks but I don’t know why this is showing runtime error even on testing.
Edit : To make more clear I am testing my program(not submitting) on the given input in the kickstart ide. If there was any compile / runtime error it would have shown in the same input at other ide.
i / p
2
2 4 5
10 10 100 30
80 50 10 50
3 2 3
80 80
15 50
20 10
Please help.
/*package whatever //do not write package name here */
import java.util.*;
class Main {
private static void dfs(int[][] stack, int[] ind, Map < String, Integer > mp, int total, int p) {
if (p < 0) return;
StringBuffer sb = new StringBuffer();
for (int i = 0; i < ind.length; i++) {
sb.append(ind[i]);
sb.append("*");
}
if (mp.containsKey(sb.toString())) {
return;
} else {
mp.put(sb.toString(), total);
}
for (int i = 0; i < stack.length; i++) {
int indexi = ind[i];
indexi++;
if (indexi < stack[i].length) {
ind[i] = indexi;
sb = new StringBuffer();
for (int j = 0; j < ind.length; j++) {
sb.append(ind[j]);
sb.append("*");
}
total += stack[i][indexi];
dfs(stack, ind, mp, total, p - 1);
total -= stack[i][indexi];
indexi--;
ind[i] = indexi;
}
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int iter = 1; iter <= t; iter++) {
int n = sc.nextInt(), k = sc.nextInt(), p = sc.nextInt();
int[][] stack = new int[n][k];
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
stack[i][j] = sc.nextInt();
}
}
int[] index = new int[n];
Arrays.fill(index, -1);
Map < String, Integer > mp = new HashMap < > ();
dfs(stack, index, mp, 0, p);
int max = Integer.MIN_VALUE;
for (Map.Entry < String, Integer > entry:
mp.entrySet()) {
if (max < entry.getValue()) {
max = entry.getValue();
}
}
System.out.println("Case #" + iter + ": " + max);
}
}
}