# -*- coding: utf-8 -*- from read_write import readIntArray, printArraySep def ensure_non_zero(x): if x == 0: return 1 return x def solution(A): # write your code in Python 3.6 a = sorted(A) for i, x in enumerate(a): if i == len(a) - 1: return ensure_non_zero(x + 1) if x <= 0: continue if x == a[i + 1]: continue xp = x + 1 if xp != a[i + 1]: return ensure_non_zero(x + 1) return ensure_non_zero(a[-1] + 1) print(solution(readIntArray()))
# -*- coding: utf-8 -*- # https://www.hackerrank.com/challenges/birthday-cake-candles/problem from read_write import readInt, sort, readIntArray, printArraySep n = readInt() arr = sort(readIntArray()) print(arr.count(arr[0]))
# -*- coding: utf-8 -*- # https://www.hackerrank.com/challenges/compare-the-triplets/problem from read_write import readIntArray, printArraySep def compare_triplets(aS, bS): a, b = 0, 0 for aV, bV in zip(aS, bS): a += 1 if aV > bV else 0 b += 1 if aV < bV else 0 return [a, b] aS = readIntArray() bS = readIntArray() printArraySep(compare_triplets(aS, bS))
# -*- coding: utf-8 -*- # https://www.hackerrank.com/challenges/plus-minus/problem from read_write import readInt, readIntArray def plusMinus(arr): plus, minus, zero = 0, 0, 0 arrCount = len(arr) for i in arr: plus += 1 if i > 0 else 0 minus += 1 if i < 0 else 0 zero += 1 if i == 0 else 0 return [plus / arrCount, minus / arrCount, zero / arrCount] n = readInt() arr = readIntArray() for i in plusMinus(arr): print('%.5f' % i)
# -*- coding: utf-8 -*- from read_write import readIntArray, printArraySep def sort(arr): if len(arr) == 1: return arr print('len', len(arr)) for x in range(len(arr) - 1): i, y = arr[x], arr[x + 1] print(i, y) if i > y: arr[x], arr[x + 1] = i, y else: arr[x], arr[x + 1] = y, i print(arr) return sort(arr[0:len(arr) - 1]) + [arr[len(arr) - 1]] # printArraySep(sort(readIntArray())) def sort_asc(arr): return sorted(arr) printArraySep(sort_asc(readIntArray()))