How to use 'HackeRank' to develop your skills

So before going any further, what is HackeRank?
HackerRank is a place where programmers from all over the world come together to solve problems in a wide range of Computer Science domains such as algorithms, machine learning, or artificial intelligence etc.

    It is one among the many other online coding practice websites which will help you to develop your coding skills. You can devise an algorithm, code it and check whether it's right or wrong at a go! The best part is that you need not provide any test cases, test cases are provided and checked by the site. All you need to do is to just submit your solution and you'd know whether your solution works or not.

Here's a step by step procedure explaining how to use HackerRank:

1. Creating an account:



Creating an account is straightforward, on the main page you have three fields to fill in your name, email, and password. After filling those details and clicking the 'sign up and start coding' button, your account will be created and you can start coding! Or you can create an account by connecting your FB account. To do this click the 'sign up' button on the top right and link your FB account.

Link to the website: https://www.hackerrank.com/

2. Getting started:

After creating your account, you are redirected to your dashboard where you can select any track to have a look at the problems related to the selected track.


For example, here when algorithm track is selected under the CORE CS category, a page containing the subdomains(to the left of the page) and related problems(right of the page) is opened.


You can select the subdomain of your choice and look beside for a problem that interests you the most and select it by clicking the solve challenge button under the question of your choice.

3. Solving the challenge:

For each challenge, the problem description, input format, constraints on inputs and desired output for the problem are provided. Even one or two examples along with explanation are given for better understanding the problem. It is essential that you understand the problem before you devise an algorithm and start coding. While coding you must make sure that your code works for all the inputs in the range which is mentioned in input constraints. One more important thing to keep in mind is the way you print output. It must be exactly in the way as they mention, if not even though your solution is correct it 's shown as incorrect.


4.  Coding:

At the end of problem details, an area is provided for you to code your solution. You can select the language of your choice by clicking the drop-down menu which displays the current language.


After typing your code, you can either run your code on few sample cases and check whether it's correct or you can directly submit your solution which would check your solution on a larger number of test cases. It is recommended that you first run your program and make sure correct results are obtained for sample cases before submitting your solution. You can either run or be submitting your code by clicking the buttons present below the code area.


5. Optimising your code:

For simple problems whose number of inputs and range of input are small, it is quite easy to pass all tests on the first submission. But as you go higher the level of problems, the number of inputs and range also increase which would require you to code a better or optimal solution rather than a naive or simple solution.

For example, consider the rotation of array problem. When we code using the simple method i.e, shifting each and every time a rotation is performed:



 and submit the solution the following result is obtained.


You could see that the test cases 5, 12, 13 and 14 show a red coloured clock mark. This indicates that your program ran out of time limit for the problem before it computed and printed the solution. In order to overcome this, you need to optimise your problem such that you don't run out of time limit. Here's an optimised version of code where we use reversing concept to rotate the array instead of shifting:




This results in successfully passing all the tests!


Hope you got an idea of using HackerRank. Any queries feel free to ask in the comments section.

Comments

Popular posts from this blog

Beginner's guide to Solving the N-Queens problem using backtracking method

PvP Chain reaction game using Python

Guide to Solving Maximal Subarray Problem using Kadane's Algorithm