Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Last active Nov 24, 2017
Embed
What would you like to do?
Python3 HackerRank
# input single integer
n = int(input().strip())
# 2 Integers in 2 lines
n, m = int(input().strip()), int(input().strip())
# 2 Integers in 1 line
n, m = input().strip().split(' ')
n, m = int(n), int(m)
# Array of integers seperated by space
a = list(map(int, input().strip().split(' ')))
# Array of integers seperated by space sorted
a = sorted(list(map(int, input().strip().split(' '))))
# print matrix
def printm(mat):
for row in mat:
print(' '.join(map(str, row)))
# print array
def printa(arr):
print(' '.join(map(str, arr)))
# Convert a number to a list of integers (base 10)
# Replace 10 with the any other base to get it working with any other base
def num2lst(num):
arr = []
if num == 0:
return [0]
c = num
while c > 0:
c, r = divmod(c, 10)
arr.insert(0, r)
return arr
# Convert a list of integer to a number (base 10)
# Replace 10 with the any other base to get it working with any other base
def lst2num(lst):
num = 0
mul = 1
for n in reversed(lst):
num += n * mul
mul *= 10
return num
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment