Skip to content

Instantly share code, notes, and snippets.

Guilherme Bazilio gbazilio

Block or report user

Report or block gbazilio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@gbazilio
gbazilio / genomic-query.py
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 = [0] * count_size
C = [0] * count_size
G = [0] * count_size
for i in xrange(len(S)):
nucleotide = S[i]
A[i + 1] += A[i] + (1 if nucleotide == 'A' else 0)
@gbazilio
gbazilio / passing-cars.py
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
@gbazilio
gbazilio / max-counter.py
Created Jan 22, 2017
Codility - Max Counter
View max-counter.py
def solution(N, A):
max_counter = last_max_counter = 0
counters = [0] * N
for k in xrange(len(A)):
current_counter = A[k]
if current_counter == N+1:
last_max_counter = max_counter
else:
@gbazilio
gbazilio / frog-jump-leaves.py
Created Jan 12, 2017
Codiligty - Frog jump leaves
View frog-jump-leaves.py
def solution(X, A):
count_array = [0] * (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
@gbazilio
gbazilio / missing-integer.py
Created Jan 11, 2017
Codility - Missing integer
View missing-integer.py
def solution(A):
count_length = len(A)
count_array = [0] * (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:
@gbazilio
gbazilio / permutation.py
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
@gbazilio
gbazilio / tape-equilibrium.py
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):
@gbazilio
gbazilio / frog-jump.py
Created Jan 8, 2017
Codility - Frog jumps
View frog-jump.py
def solution(X, Y, D):
return int(math.ceil((Y - X) / float(D)))
@gbazilio
gbazilio / missing-element.py
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
@gbazilio
gbazilio / odd-occurrences.py
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.