You are viewing a single comment's thread. Return to all comments →
Here's a C++ solution using sliding window technique:
bool isvalid(map<char,int> a, int l){ if(a['A'] <= l && a['G'] <= l && a['T'] <= l && a['C'] <= l) return true; return false; } int steadyGene(string gene) { int n = gene.size(), mini = n; map<char,int> am; for(char c: gene){ am[c]++; } if(isvalid(am, gene.size()/4)){ return 0; } int i = 0, j = 0; while(j < n){ if(isvalid(am, gene.size()/4)){ am[gene[i]]++; i++; mini = min(mini, (j - i + 1)); } else{ am[gene[j]]--; j++; } } return mini; }
Seems like cookies are disabled on this browser, please enable them to open this website
Bear and Steady Gene
You are viewing a single comment's thread. Return to all comments →
Here's a C++ solution using sliding window technique: