Skip to content

Instantly share code, notes, and snippets.

@gbazilio
Created January 29, 2017 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gbazilio/d36a05693dc804ec2a2630095b116852 to your computer and use it in GitHub Desktop.
Save gbazilio/d36a05693dc804ec2a2630095b116852 to your computer and use it in GitHub Desktop.
Codility - Genomic range query
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)
C[i + 1] += C[i] + (1 if nucleotide == 'C' else 0)
G[i + 1] += G[i] + (1 if nucleotide == 'G' else 0)
for m_index in xrange(m_size):
range_from = P[m_index]
range_to = Q[m_index] + 1
if A[range_to] > A[range_from]:
P[m_index] = 1
elif C[range_to] > C[range_from]:
P[m_index] = 2
elif G[range_to] > G[range_from]:
P[m_index] = 3
else:
P[m_index] = 4
return P
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment