Created
January 29, 2017 16:25
-
-
Save gbazilio/d36a05693dc804ec2a2630095b116852 to your computer and use it in GitHub Desktop.
Codility - Genomic range query
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) | |
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