Skip to main content

Online Judges

Why, What and How?

Online judges: Where every line of code gets a fair trial, and bugs are considered 'guilty' until proven innocent.

As Simon Sinek says: Let's start with Why!

Imagine you're writing the code for a DSA problem in the college exam hall. I'm sure you'll agree that, in this case, your DSA professor and/or TA will be the one(s) who will check if the code is correct.

Now the question is, if somebody wants to conduct a competition/contest online, where thousands of people from all over the world will participate, and on top of that if the contest has rounds that happen every week, won't it be a task to check all those codes manually?

This is why Online Judges originated.

Moreover, it is not just about an online contest; imagine someone who wants to build an extensive library of DSA problems where people can come, submit their code, and check if they are progressing in their coding capabilities. We'll also need an automated testing system in that scenario, right?

What is an OJ?

An Online Judge is simply a software that helps solve the problem mentioned in the Why section. Many websites conduct programming contests regularly and make good use of their online judges. Some of these platforms are:

  1. Leetcode
  2. CodeForces

And more...

Well, all this is fine, but how does it work?

Cool, let's get to it.

Tell me this: What would you do if you were to check whether your younger cousin knows how to multiply two numbers correctly?

You'd probably give them a few multiplication problems and check if they answer correctly, right? So, why not also use a similar technique for checking the correctness of codes?

This is precisely how this whole system works in the real world. The team of Problem Setters and Testers work together to develop a set of test cases , and the codes of participants are run on them to check if the output matches the correct output. Now, what test cases to use and how many to use? It is up to the experts to decide what cases they need to cover to ensure the code is correct and efficient enough.

Now, the job of the Online Judge is to:

  1. Compile/interpret the code.
  2. Run it against the set test cases.
  3. Check each case to see if the code:
    • Can generate an output within the given time limit.
    • The generated output matches the expected one.

Conclusion

In conclusion, Online Judges are pivotal in automating the evaluation process for coding competitions and learning platforms. By compiling, running, and testing code against predefined cases, they efficiently assess the correctness and efficiency of participants' solutions, making large-scale contests and coding problems' libraries accessible and manageable worldwide.