This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(X, Y, D): | |
return int(math.ceil((Y - X) / float(D))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
NewerOlder