HackerRank and the Euler Challenges

I wanted to do a spotlight on a site which I believe would be of great interest to programming enthusiasts: HackerRank.

HackerRank Logo

HackerRank is a site which allows you to hone your programming skills in a large number of different languages by providing you with problems to solve. The site is completely free and has a very smooth and sleek look. The problems vary in difficulty from easy to very difficult. Easy problems may require just a few lines of code while harder problems may require a lot more, with even more care given to algorithm design.

HackerRank supports a large number of languages, including C, C++, Python, C#, Java, VB.Net. HackerRank also supports functional programming languages like Haskell, Lisp and Scala. As part of the challenge, some problems only allow you to use these functional languages.

The site hosts frequent competitions where programmers from all around the world go head-to-head. The winner (determined by the highest score) can win some great prizes. You can participate in many different types of competitions. These range from Weekly Challenges, where you solve a new problem every day, to Ad Infinitum math challenges, where you need a good understanding of math to overcome the challenges.

The problem format is simple. You are provided with a problem description and a problem input. It is your job to write a program which reads the problem input and outputs the solution in the format required. You get a few test cases as an example to test out your code.

When you are confident with your solution, you submit it for further testing. Your code is then tested using a large number of test cases for accuracy and efficiency. Yes, efficiency is also tested because your program has an execution time limit. The time limit varies depending on the programming language. For example, Python has a 10-second time limit while C has a 2-second time limit, because Python code runs slower than C.

Solving problems rewards you with “Hackos”, depending on the difficulty of the problem solved. You can use Hackos to “buy” test cases used when you submit a piece of code for testing. This applies to all problems except in competitions, where you can buy them after the competition has ended. Buying a test case gives you access to the input and the expected output. For us perfectionists out there, it gives us valuable information in debugging our code if a specific test case fails. We see what the input is and what the expected output should be.

Every user has their own public profile, which keeps track of their competition score over time and provides other statistics. You can input any personal information you which, such as your country of residence so that its flag displays on the leaderboard for competitions. The profiles are extremely simple, but I do like them because of that.

I really like HackerRank because it does focus on efficiency in code. For some problems, a simple brute-force solution won’t fly. It may pass the first few test cases, but will fail the later ones. HackerRank tests your code at boundary conditions using these tests. What this does is improve your skill as a programmer. It makes you think more carefully about algorithm efficiency. In turn, you are able to write faster-running programs that are more elegant. As far as my own personal experience goes, I did learn two important things about algorithm efficiency, which I will outline in later posts:

  1. Dictionaries are a lot faster than standard arrays when you need to check if values exist. For the longest time, I would try and run my code using a regular array. However, when the number of elements in that array get very large, even a binary search algorithm on an already-sorted array can take a long time. My code failed using the binary search, but executed in less than one second when using dictionaries.
  2. When trying to concatenate a large number of strings, it is always better to use a String Builder, rather than concatenate them manually. Again, when my code failed with string concatenation, it could complete execution in less than one second.

Lately, HackerRank has started putting up problems from the Euler Project¬†as part of a competition that appears to last forever (at least, at the time of this post). If you’re not familiar with Euler Project, it is a site which poses various mathematics-related problems. You can solve these problems either programmatically or by hand. You solve the problem and input the solution on the site. Problems are easy to solve at the start, but get significantly harder as you go through the list.

HackerRank has taken these problems to the next step. Instead of a single case scenario provided in the Euler Project, you will be provided with a number of different test cases. You must solve the solutions programmatically in order to satisfy this requirement. For example, a problem from the Euler Project may ask you to determine the 1,000,000th prime number. This can easily be solved by looking the answer up (either from a list or even using Wolfram Alpha).

However, the HackerRank problem will tell you that each test case will provide you with a list of numbers, N. The ouput should contain a list of the N’th prime number. So, if you were provided with a list [10,5,1000000], you’d be expected to output a list of the 10th, 5th and 1,000,000th prime number respectively. This removes the “look the answer up” aspect of the problem and forces you to think about solving the problem using an algorithm that works for all possible cases.

I do enjoy HackerRank and after the addition of the Euler Project problems, it has become even better. It forces people to think about the quality of their programs, something which I feel people tend to neglect due to faster computers. If you do enjoy programming and/or mathematics, you should definitely check out the HackerRank and/or the Euler Project. You won’t be disappointed.

Do you know of any other similar sites? What do you think about HackerRank? Is there anything they do well? What about things they could improve on? Let me know in the comments!

This entry was posted in Spotlight. Bookmark the permalink.

2 Responses to HackerRank and the Euler Challenges

  1. test says:

    Does your site have a contact page? I’m having a tough time
    locating it but, I’d like to send you an email. I’ve got some creative ideas for your blog you might be interested in hearing.
    Either way, great site and I look forward to seeing it improve over time.

Leave a Reply

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