Chinmaya Bisoi

Posted on

# Getting Started With Hackerrank Using Python | For Absolute Beginners

## The Intro

Data Structures and Algorithms(DSA) are a necessity to land a Good ass Technical job. And when it comes to DSA, people turn to popular websites like `Leetcode`, `Hackerrank`, `Hackerearth` and many more.

That being said, Starting anew can be difficult and sometimes overwhelming and newbies can find it difficult to figure out the ins and outs of the platform they use (How to take Input(s), how to produce the proper Output(s)

## Hackerrank with Python

Let's say you come across this kind of question, where you have input
and output like:

Then the output would be given using `print` and one way to take in inputs would be individually take all four inputs like x,y,z,n as given below

``````if __name__ == '__main__':
x = int(input())
y = int(input())
z = int(input())
n = int(input())
print ([[a,b,c] for a in range(0,x+1) for b in range(0,y+1) for c in range(0,z+1) if a + b + c != n ])

``````

The other way to take in four inputs would be to use a for loop to store the inputs in a list.

Let's see another example
Consider the given inputs and the following code:

``````if __name__ == '__main__':
n = int(input())
arr = map(int, input().split())
``````

What the above code does is it assigns 5 to n ; then checks the second line to find `2 3 6 6 5` where the input().split() splits the string `2 3 6 6 5` to a list with the following items :
`2` `3` `6` `6` `5`

The map function then converts the items to integer type and we get a list arr = [2,3,6,6,5] where each item is an integer.