Skip to content

Instantly share code, notes, and snippets.

@xeonqq
xeonqq / codility_NumberSolitaire.py
Created August 31, 2015 11:21
In a given array, find the subset of maximal sum in which the distance between consecutive elements is at most 6.
# you can use print for debugging purposes, e.g.
# print "this is a debug message"
def solution(A):
n = len(A)
MIN_INT = -n * 20000
v = [A[0]]+(n-1)*[MIN_INT]
for i in xrange(1, n):
for j in xrange(1, 7):
if j <= i:
@xeonqq
xeonqq / Codility_MinMaxDivision.py
Last active August 29, 2015 14:26
Divide array A into K blocks and minimize the largest sum of any block.
def blockPossible(A, bound, K):
s = A[0]
blocks = 1;
for a in A[1:]:
s += a
if s>bound:
blocks+=1
s=a
if blocks > K:
return False
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.