Skip to content

Instantly share code, notes, and snippets.

@JaDogg
Last active November 24, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JaDogg/c349b523ae91f622a0e56cd1d3594ee1 to your computer and use it in GitHub Desktop.
Save JaDogg/c349b523ae91f622a0e56cd1d3594ee1 to your computer and use it in GitHub Desktop.
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