Entries from 2019-04-01 to 1 month

MaxDoubleSliceSum 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(A): fromStartMaxEnding = [0] * len(A) for i in range(1, len(A)-1): fromStartMaxEnding[i] = max(0, fromStartMaxEnding[i-1]+A[i]) fromEndMaxEnding = [0] * len(A) for i in ra…

MaxSliceSum 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(A): allNegative = 1 maxNegative = -1 * 2**31 for i in range(len(A)): if A[i] > 0: allNegative = 0 break elif A[i] > maxNegative: maxNegative = A[i] if allNegative == 1: re…

MaxProfit 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(A): # calculate the difference everyday diff = [0] * len(A) for i in range(1, len(A)): diff[i] = A[i]-A[i-1] # print(diff) # find the max slice maxEnding = 0 maxSlice = 0 …

EquiLeader 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(A): # check if A has a dominator length = len(A) stack = [0]*length size = 0 for i in range(length): if size == 0: stack[size] = A[i] size += 1 elif stack[size-1] != A[i]:…

Dominator 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(A): stack = [0]*len(A) size = 0 index = -1 count = 0 for i in range(len(A)): if size == 0: stack[size] = A[i] size += 1 else: if stack[size-1] != A[i]: size -= 1 else: sta…

StoneWall 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(H): block = 0 stack = [0]*len(H) size = 0 for i in range(len(H)): while size > 0 and stack[size-1] > H[i]: size -= 1 if size > 0 and stack[size-1] == H[i]: pass else: bloc…

Nesting 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(S): stack = [0]*len(S) size = 0 for i in range(len(S)): if S[i] is "(": stack[size] = S[i] size += 1 else: if size is 0: return 0 else: size -= 1 if size is 0: return 1 re…

Brackets 100% Solution in python

Question app.codility.com My Solution app.codility.com def solution(S): stack = [0]*len(S) size = 0 for i in range(len(S)): if S[i] is "(" or S[i] is "{" or S[i] is "[": stack[size] = S[i] size += 1 else: if size is 0: return 0 elif S[i] i…

Fish 100% Solution in Python

Notice Recently I got some codility challenges from companies and they don't allow me to use javascript. As a results, I learn the basic coding style in python from the very beginning on YouTube Python Programming Tutorial - 1 - Installing…