Code showing Runtime error on testing on google kickstart editor, while it is working on other compilers

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);

  }
 }
}
1 Like

If there is any compilation error then also it will give you RUNTIME
else if it is array index bound or if you have not use long or big int then also it may throw runtime .
Please look on this issue.

Please read the edit. I am testing on the ide with the given input not submitting.

@vijju123 help

Well it’s too late to reply but today I also faced the same issue and solved it. So I think it might help.
I did it for c++ .
Normal IDE’s allow dynamic memory allocation of upto 5*10^5 inside a function and about 10^8 outside any function(global variables).
But Kickstart’s IDE is a bit different and the limits are less in it for inside a function allocation. So it causes memory allocation error giving runtime error.
Check it. It worked for c++. Hope it might help.

Problem link

Solution that gave runtime error (see line 66)

Accepted sol. Only changed array memory allocation. See line 18 and 54

1 Like

same error i have got

If you code in JAVA, just make your class name as “Solution”.

8 Likes