in

Solved: Google Coding Competitions Runtime Error (RE) Issue (JAVA)

Google hosts a bunch of coding contests every year, some of which are Code Jam, Kickstart and Hash Code. Google uses the same web IDE in each of its contests where you need to write your code and submit it. But if you’re using it for the first time ever, no matter which coding contest you’re participating in or practising for, there’s a high chance that the IDE will tell you that your program encountered a runtime error.

The error message simply says “Sample Failed: RE“. And even when you click on the eye button, it says “RE“, which means Runtime Error. It does not provide any further info regarding why the error occurred. And the most surprising thing is, in most cases, your code will run fine in any other IDE other than Google’s Coding Competition IDE.

Google Coding Competition Runtime Error

I too came across this problem some time ago and even after visiting many forums, I didn’t find the answer. But then, the idea struck my mind and I finally solved the Runtime Error in my Google Kickstart Code. This solution to fix the runtime error will work in all Google Coding Competitions, e.g. Code Jam, Kickstart and Hash Code.

How To Fix The Runtime Error In Google Code Jam/Kickstart/Hash Code

Well, this problem is caused by nothing but your program’s class name.

Google follows a convention where you must always define the Main class of your program (the class that contains the main method) as “public class Solution“.

Runtime Error Fixed

Thus, to fix the runtime error issue, all you gotta do is, rename your class declaration to “public class Solution”

This is a weird convention set by Google. The more annoying part is that it is nowhere mentioned about this convention and thus programmers like I and you spend hours looking for the reason why the compiler is throwing us a Runtime Error even though the other compilers are running it perfectly.

I hope this article helped you solve the Runtime Error issue. Do let me know in the comments section below if there’s any other problem that you’re facing with the Google Coding Contests IDE. I will try my best to help you out!

Do check out some other posts on my site for more cool stuff! Have a great day ahead!

What do you think?

106 Points
Upvote Downvote

Written by Anirban Roy

Anirban is a full-stack developer and an SEO expert. He has 6 years of experience in web development and software engineering. With a passion for writing, he has been blogging since 2017.

Leave a Reply

Your email address will not be published. Required fields are marked *

24 Comments

  1. Thank you so much, this works. And it’s pretty weird why would Google set such conventions. But that’s how it is… Anyways thanks for discussing it in detail.

    • This kind of false error doesn’t happen in the case of Python. If you’re facing a runtime error in Python, that’s most probably due to a real mistake in your code.

          • https://ide.geeksforgeeks.org/syp9meGSoe
            The input I am taking here is the same as the sample input given in the question in kickstart round D today. Here the code is working fine. But there it is showing “Sample Failed: RE”.

          • Yeah, I see it now. This seems to be another undiscovered bug of Google Coding Platform that is generating false Runtime Errors. This article is dedicated to Java. However, thanks for informing me that this problem is occurring with Python as well. I will do some more research on this and publish a new article on that topic separately. You will be notified via an e-mail in case the solution is found. However, if you find the solution to that problem before, you can mail it to [email protected] and your solution will be posted on this website, with full credits going to you. Thanks.

  2. i already named my class as “Solution” but still i am facing this issue. my java code runs on any other online compiler but it shows RE on kickstart. can you help me with this?

    my code is attached below.
    https://docs.google.com/document/d/1vx-mXGwRlrSRyVuMZSy4VlX5CV2lbWkYnfywtjy39sw/edit?usp=sharing

    • Hi Mustansir,

      There’s a REAL ERROR in your code. You are trying to store an int value in an array without specifying the index, which is causing the error.
      Please take a look at the picture given below for your reference.

      Google Kickstart Runtime Error Issue Solved

  3. hello.. I have my program running perfectly and also my class name is “Solution”. What is the issue with the code now?

    import java.util.*;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;

    public class Solution
    {
    public static void main(String []args)
    {
    Scanner sc=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
    int test=sc.nextInt();
    if(test>=1 && test<=100){
    for(int t=1;t<=test;t++)
    {
    int n=sc.nextInt();
    int b=sc.nextInt();
    int arr[]=new int[n];
    for(int i=0;i=0)
    {
    b=b-arr[i];
    count++;
    i++;
    }

    return count-1;
    }
    }

    • Hi Tripti,
      Your code has the following two errors:
      1. On line 17, the for loop is invalid. The syntax for a for loop in Java is for(initialization;condition;changes). Although you can skip one or more parameters, but the two semicolons are mandatory, however, your code misses a semicolon after the second parameter.
      2. On line 23, I believe you forgot to end the outer for loop. The compiler cannot parse your code properly due to the missing closing bracket.

      Take a look at the picture below for reference:

      Google coding contest error solution

    • As far as I know, in most of the problems you don’t need to create packages. You can just write other classes alongside the Solution class and use their objects normally. Google doesn’t allow you to host packages, so how can you expect it to not throw an error when you try to declare a package name, which neither exists, nor can be created.

  4. Hey! I am facing a runtime error even though my class name is Solution. So can you please look into it?
    Here is my code:

    import java.util.*;

    public class Solution {

    public static String getRuler(String kingdom) {
    if (isVowel(kingdom.charAt(kingdom.length() – 1))) {
    return “Alice”;
    } else if (kingdom.charAt(kingdom.length() – 1) == ‘y’ || kingdom.charAt(kingdom.length() – 1) == ‘Y’)
    return “nobody”;
    return “Bob”;
    }

    public static boolean isVowel(char c) {
    return (c == ‘a’ || c == ‘A’ || c == ‘e’ || c == ‘E’ || c == ‘i’ || c == ‘I’ || c == ‘O’ || c == ‘o’ || c == ‘u’
    || c == ‘U’);
    }

    public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int T = in.nextInt();

    for (int t = 1; t <= T; ++t) {
    String kingdom = in.next();
    System.out.println(
    "Case #" + t + ": " + kingdom + " is ruled by " + getRuler(kingdom) + ".");
    }
    }
    }

  5. Does anyone know how to fix the same error for Python?!
    The weird thing here is that the code runs flawlessly on the sample input (the one given with the problem statement) but fails on the first set!
    Thanks in advance.

  6. My program is getting runtime error despite naming the class as Solution…
    kindly check as its giving right solution on Intellij IDE.
    import java.util.*;

    public class Solution {

    public static void main(String[] args) {
    Scanner sc= new Scanner(System.in);
    int t= sc.nextInt();
    int n, sum, a[],temp;
    for (int i=1;i<=t;t++){
    sum=1;
    n= sc.nextInt();
    a=new int[n];
    for (int j=0;j<n;j++)
    a[j]= sc.nextInt();
    for (int k=0;k<n;k++){
    for (int j=1;ja[j]){
    temp=a[j-1];
    a[j-1]=a[j];
    a[j]=temp;
    }
    }
    }

    int c=1,l=a[0];
    for (int k=1;k<n;k++){
    if (a[k]==l)
    sum+=c;
    else
    {
    l=a[k];
    sum+=++c;
    }
    }
    System.out.println("Case #"+i+": "+sum);
    }
    }
    }

  7. Hey. I renamed the class as Solution and still I am getting Runtime Error in Java. I even tried to run Starter Code provided by Google only and it is also giving Runtime Error.

    Here is my code:

    import java.util.Scanner;
    import java.util.HashSet;
    import java.util.Arrays;

    public class Solution {

    private static HashSet vowels = new HashSet(Arrays.asList(‘A’,’E’,’I’,’O’,’U’,’a’,’e’,’i’,’o’,’u’));

    public static void main(String[] args) {

    Scanner in = new Scanner(System.in);

    int tmax = in.nextInt();

    for (int t=0; t<tmax; t++) {

    String kingdom = in.next();

    System.out.println("Case #" + t + ": " + kingdom + " is ruled by " + getRuler(kingdom) + ".");

    }

    }

    private static String getRuler(String kingdom) {

    char lastChar = kingdom.charAt(kingdom.length() – 1);

    if (vowels.contains(lastChar)) return "Alice";

    if (lastChar == 'y' || lastChar == 'Y') return "nobody";

    return "Bob";

    }

    }

    Here is starter code by Google:

    import java.util.*;

    public class Solution {

    private static String getRuler(String kingdom) {

    String ruler = "";
    return ruler;
    }

    public static void main(String[] args) {
    try (Scanner in = new Scanner(System.in)) {
    int T = in.nextInt();

    for (int t = 1; t <= T; ++t) {
    String kingdom = in.next();
    System.out.println("Case #" + t + ": " + kingdom + " is ruled by " + getRuler(kingdom) + ".");
    }
    }
    }
    }

    I am working on 2022 Kickstart Practice 1 Centauri Prime Problem

  8. I am getting runtime error in kickstart but it is running fine on other platforms.

    import java.io.*;
    import java.util.*;
    public class Solution
    {
    public static void main() throws IOException
    {
    Scanner sc=new Scanner(System.in);
    Scanner sc1=new Scanner(System.in);
    int t,l,n,te=1,i;
    t=sc.nextInt();
    while(t>0)
    {
    l=sc.nextInt();
    n=sc.nextInt();
    int di[]=new int[n];
    char c[]=new char[n];
    for(i=0;i<n;i++)
    {
    di[i]=sc.nextInt();
    c[i]=sc.next().charAt(0);
    }
    int s=0,lap=0,lap1=0,m=0;
    char ch=c[0];
    for(i=0;ilap1&&ch==c[i])
    {
    m=m+(lap-lap1);
    }
    else if(ch!=c[i]&&(lap-lap1)>1)
    {
    m=m+(lap-lap1)-1;
    }

    lap1=lap;
    ch=c[i];
    }
    System.out.println(“Case #”+te+”:”+” “+m);
    te=te+1;
    t=t-1;
    }
    }
    }