Instantly share code, notes, and snippets.

# Guilherme Baziliogbazilio

• Sort options
Created Jan 29, 2017
Codility - Genomic range query
View genomic-query.py
 def solution(S, P, Q): m_size = len(P) count_size = len(S) + 1 A =  * count_size C =  * count_size G =  * count_size for i in xrange(len(S)): nucleotide = S[i] A[i + 1] += A[i] + (1 if nucleotide == 'A' else 0)
Created Jan 29, 2017
Codility - Passing cars
View passing-cars.py
 def solution(A): passing_cars = 0 east_cars = 0 for index in xrange(len(A)): if A[index] == 1: passing_cars += east_cars else: east_cars += 1
Created Jan 22, 2017
Codility - Max Counter
View max-counter.py
 def solution(N, A): max_counter = last_max_counter = 0 counters =  * N for k in xrange(len(A)): current_counter = A[k] if current_counter == N+1: last_max_counter = max_counter else:
Created Jan 12, 2017
Codiligty - Frog jump leaves
View frog-jump-leaves.py
 def solution(X, A): count_array =  * (X) leaves = 0 for index in xrange(len(A)): if count_array[A[index] - 1] == 0: count_array[A[index] - 1] = 1 leaves += 1 if leaves == X: return index return -1
Created Jan 11, 2017
Codility - Missing integer
View missing-integer.py
 def solution(A): count_length = len(A) count_array =  * (count_length + 1) for value in A: if value > 0 and value <= count_length: count_array[value-1] += 1 for index in xrange(len(count_array)): if count_array[index] == 0:
Created Jan 9, 2017
Codility - Permutation
View permutation.py
 def solution(A): n = len(A) A_sum = sum(set(A)) ideal_sum = n*(n+1)/2 return 1 if A_sum == ideal_sum else 0
Created Jan 8, 2017
Codility - Tape equilibirum
View tape-equilibrium.py
 def solution(A): sum_of_part_two = sum(A) min_difference = None sum_of_part_one = 0 for i in xrange(1, len(A)): sum_of_part_one += A[i-1] sum_of_part_two -= A[i-1] difference = abs(sum_of_part_one - sum_of_part_two) if (min_difference == None):
Created Jan 8, 2017
Codility - Frog jumps
View frog-jump.py
 def solution(X, Y, D): return int(math.ceil((Y - X) / float(D)))
Created Jan 8, 2017
Codility - Missing element
View missing-element.py
 def solution(A): A_length = len(A) array_sum = sum(A) complete_sequence_sum = (A_length * (A_length + 1) / 2) + (A_length + 1) return complete_sequence_sum - array_sum
Last active Jan 17, 2017
Codility - Odd occurrences
View odd-occurrences.py
 def solution(A): A = sorted(A) for index in range(0, len(A), 2): next_index = index+1 if next_index >= len(A) or A[index] != A[index+1]: return A[index]
You can’t perform that action at this time.