HackerRank - Advance Your Coding Through Problem Solving
Written by Nikos Vaggalis   
Tuesday, 31 May 2016
Article Index
HackerRank - Advance Your Coding Through Problem Solving
Challenging Community

This is very interesting proposition in the "learn to code" e-learning field. HackerRank uses a variety of methods to reinforce learning: hands-on problem solving through trial and error, gamification with points, ranking and awards and constructive competition through contests and hackathons, all combined combined into a single package.



HackerRank's mission objectives are to help students improve their coding, make personal connections through interest sharing and team working, and, for high achievers, even the opportunity of job offers. 

There is no restriction as to where you start or what you can do concurrently and students can jump in from one of three potential entry points, depending on their level of experience in programming.

Start by learning concepts

The first entry point is through 30 Days of Code, where you get  to improve your skills by coding for 30 days in a row, a mix of tutorials and challenge solving.


hackerrank intro


Here the material is targeted at novices as the tutorials take you step by step through the concepts of programming using Java as the example language. Each day you get acquainted with a new concept of programming:

On Day 0 you start with 'Hello World', while on the other days,

  • Day 1: Data Types,
  • Day 2: Operators
  • Day 3: Intro to Conditional Statements
  • ....
  • Day 12: Inheritance
  • Day 13: Abstract Classes
  • ....
  • Day 21: Generics
  • Day 28: RegEx, Patterns, and Intro to Databases
  • and finally on Day 29: Bitwise AND

The challenges are time locked and a new one unlocks the day after the its predecessor completion. This is done to give students the time necessary for absorbing each concept, avoiding overload with too many things at once.

Back to Day 0, in order to get past the 'Hello World' test, you have to (optionally) follow this section's tutorial which gives a brief introduction to the very basics, like what a Class, a variable, an object and a method are.

However, the explanations provided are certainly not addressed to those totally novice to programming. For example:

At its most basic level, a class is a collection of variables (fields) and functions called methods. A program is a collection of classes

[In] object-Oriented programming, a method is a type of function that operates on the fields of a class

Object is an instance (or variable) of a class

More effort is put into explaining what a variable is:

Think of this as a name (identifier) that points to (references) a location in memory where information associated with that name can be stored.....

If we want to declare a variable of type DataType named myVar1 and initialize it to be value, we write:

DataType myVar1 = value;

In English, the above code is basically saying: "I'm creating a variable named myVar1; it refers to something of type DataType, and is assigned an initial value of value.

Note: The = operator is called the assignment operator, so you should interpret = as the English phrase "[left operand] is assigned the value of [right operand]

As you can see, there's a bit of a mismatch between the experience required for mastering the concepts of Class and Method with that needed to grasp the concept of the variable. The former case treats the student as someone with a little programming experience and the latter as someone who has never seen code before.

Anyway, what you actually have to do is

save a line of input from stdin to a variable, print on a single line, and finally print the value of your variable on a second line

and you are presented with what the expected outcome should be.

Although the relevant tutorial is in Java, there is nothing stopping you from completing the challenge by opting for one of the many supported languages, ranging from Ada(!) through C++ and to Whitespace!

For the full list of the supported languages and their companion libraries that come installed with, check the Environment and Samples page.

Of course it goes without saying that with the exception of the few exercises (e.g. Maths) that make use of those libraries, you are solely relying on the core language capabilities.

Choosing Perl for example, loads the following template:

# get a line of input from stdin and save it to our variable
my $
inputString =<STDIN>
# Your first line of output goes here 

print "Hello, World.\n";
# Write the second line of output

The student has to amend this to produce the expected output, which in this case just requires the addition of :
print  $inputString;

This is trivial but it doesn't remain that easy for long as you progress further through the days, but the notion remains the same in that you are presented with a pre-made template which you have to tweak to reach a specified goal.

When "Run code" is clicked, a 'bot' runs and evaluates your code, spitting out any syntax errors found and checking whether it provided the expected result or not. After you get the go ahead, you have to press the "Submit" button, although you can still make changes and submit it again.


And here is where the gamification part steps in. As soon as a challenge is completed you get awarded with points and start to climb the rankings in the League. How far you will get depends on the ranking algorithm's inner workings, which takes  many parameters into account (see Scoring) for assigning you a position.

Rankings aside, the Leaderboard also hosts the other player's solutions, so that you can compare yours to  theirs. You can also check what the solution would look like in another language, just like reading a Rosetta stone.

In this case the player in the number 1 spot came up with the following :


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
   string inputString; // declare a variable to hold our input
   getline(cin, inputString); // get a line of input from cin and save it to our variable
   // Your first line of output goes here
   cout << "Hello, World." << endl;
   cout << inputString << endl;
   // Write the second line of output

   return 0;


The 30 Days stream seems to be a good option for beginners, but if you are familiar with the basics of programming it's preferable to start with the Warmup Challenges of the Algorithms domain to get the hang of the platform.


hackerrank warmup

Last Updated ( Wednesday, 07 December 2016 )