A DNA sequence can be represented as a string consisting of the letters A, C, G and T, which correspond to the types of successive nucleotides in the sequence. Each nucleotide has an impact factor, which is an integer. Nucleotides of types A, C, G and T have impact factors of 1, 2, 3 and 4, respectively. You are going to answer several queries of the form: What is the minimal impact factor of nucleotides contained in a particular part of the given DNA sequence?
The DNA sequence is given as a non-empty string S = S[0]S[1]...S[N-1] consisting of N characters. There are M queries, which are given in non-empty arrays P and Q, each consisting of M integers. The K-th query (0 ≤ K < M) requires you to find the minimal impact factor of nucleotides contained in the DNA sequence between positions P[K] and Q[K] (inclusive).
For example, consider string S = CAGCCTA and arrays P, Q such that:
P[0] = 2 Q[0] = 4 P[1] = 5 Q[1] = 5 P[2] = 0 Q[2] = 6The answers to these M = 3 queries are as follows:
- The part of the DNA between positions 2 and 4 contains nucleotides G and C (twice), whose impact factors are 3 and 2 respectively, so the answer is 2.
- The part between positions 5 and 5 contains a single nucleotide T, whose impact factor is 4, so the answer is 4.
- The part between positions 0 and 6 (the whole string) contains all nucleotides, in particular nucleotide A whose impact factor is 1, so the answer is 1.
Write a function:
class Solution { public int[] solution(String S, int[] P, int[] Q); }
that, given a non-empty string S consisting of N characters and two non-empty arrays P and Q consisting of M integers, returns an array consisting of M integers specifying the consecutive answers to all queries.
Result array should be returned as an array of integers.
For example, given the string S = CAGCCTA and arrays P, Q such that:
P[0] = 2 Q[0] = 4 P[1] = 5 Q[1] = 5 P[2] = 0 Q[2] = 6the function should return the values [2, 4, 1], as explained above.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [1..100,000];
- M is an integer within the range [1..50,000];
- each element of arrays P and Q is an integer within the range [0..N - 1];
- P[K] ≤ Q[K], where 0 ≤ K < M;
- string S consists only of upper-case English letters A, C, G, T.
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P-1 >= 0 ? mHolder[nucleotide].mOcurrencesSum[P-1] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
P:2,Q:4 ,N: 0 Qn: 0 Pn:1 ,min:3 [0, 1, 0, 0, 0, 0, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:0 ,min:3 [1, 0, 0, 2, 3, 0, 0] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 0, 0, 0, 0, 2]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P-1 >= 0 ? mHolder[nucleotide].mOcurrencesSum[P-1] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['A', [0], [0]]
P:2,Q:4 ,N: 0 Qn: 0 Pn:1 ,min:3 [0, 1, 0, 0, 0, 0, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:0 ,min:3 [1, 0, 0, 2, 3, 0, 0] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 0, 0, 0, 0, 2]
function result: [1, 2, 2]
P:0,Q:1 ,N: 0 Qn: 0 Pn:0 ,min:3 [1, 0] P:0,Q:1 ,N: 1 Qn: 1 Pn:0 ,min:3 [0, 1]
function result: [1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P-1 > 0 ? mHolder[nucleotide].mOcurrencesSum[P-1] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['A', [0], [0]]
P:2,Q:4 ,N: 0 Qn: 0 Pn:1 ,min:3 [0, 1, 0, 0, 0, 0, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:0 ,min:3 [1, 0, 0, 2, 3, 0, 0] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 0, 0, 0, 0, 2]
function result: [1, 2, 2]
P:0,Q:1 ,N: 0 Qn: 0 Pn:0 ,min:3 [1, 0] P:0,Q:1 ,N: 1 Qn: 1 Pn:0 ,min:3 [0, 1]
function result: [1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['A', [0], [0]]
P:2,Q:4 ,N: 0 Qn: 0 Pn:0 ,min:3 [0, 1, 0, 0, 0, 0, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:0 ,min:3 [1, 0, 0, 2, 3, 0, 0] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 0, 0, 0, 0, 2]
function result: [1, 2, 2]
P:0,Q:1 ,N: 0 Qn: 0 Pn:0 ,min:3 [1, 0] P:0,Q:1 ,N: 1 Qn: 1 Pn:0 ,min:3 [0, 1]
function result: [1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['A', [0], [0]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 1, 2]
P:0,Q:1 ,N: 0 Qn: 1 Pn:0 ,min:3 [1, 1]
function result: [1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['ACCCACCCA', [1, 1, 5], [3, 4, 7]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 1, 2]
P:0,Q:1 ,N: 0 Qn: 1 Pn:0 ,min:3 [1, 1]
function result: [2, 1, 2]
P:1,Q:3 ,N: 0 Qn: 1 Pn:1 ,min:3 [1, 1, 1, 1, 2, 2, 2, 2, 3] P:1,Q:3 ,N: 1 Qn: 3 Pn:1 ,min:3 [0, 1, 2, 3, 3, 4, 5, 6, 6] P:1,Q:4 ,N: 0 Qn: 2 Pn:1 ,min:3 [1, 1, 1, 1, 2, 2, 2, 2, 3] P:5,Q:7 ,N: 0 Qn: 2 Pn:2 ,min:3 [1, 1, 1, 1, 2, 2, 2, 2, 3] P:5,Q:7 ,N: 1 Qn: 6 Pn:4 ,min:3 [0, 1, 2, 3, 3, 4, 5, 6, 6]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['ACCCACCCA', [1, 1, 5], [3, 4, 7]]
function result: [1, 1, 2]
function result: [2, 1, 2]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['GT', [0, 0, 1], [0, 1, 1]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AAGT', [0, 2, 2, 3], [0, 2, 3, 3]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = P > 0 ? mHolder[nucleotide].mOcurrencesSum[P] : 0;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AAGT', [0, 2, 2, 3], [0, 2, 3, 3]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 3, 4, 4]
P:2,Q:3 ,N: 0 Qn: 2 Pn:2 ,min:3 [1, 2, 2, 2] P:2,Q:3 ,N: 1 Qn: 0 Pn:0 ,min:3 [0, 0, 0, 0] P:2,Q:3 ,N: 2 Qn: 1 Pn:1 ,min:3 [0, 0, 1, 1] P:2,Q:3 ,N: 3 Qn: 1 Pn:0 ,min:3 [0, 0, 0, 1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
}
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AAGT', [0, 2, 2, 3], [0, 2, 3, 3]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 3, 3, 4]
P:2,Q:3 ,N: 0 Qn: 2 Pn:2 ,min:3 [1, 2, 2, 2] P:2,Q:3 ,N: 1 Qn: 0 Pn:0 ,min:3 [0, 0, 0, 0] P:2,Q:3 ,N: 2 Qn: 1 Pn:0 ,min:3 [0, 0, 1, 1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
}
//System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
// " Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
//System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
}
//System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
// " Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
//System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['A', [0], [0]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
}
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 2, 2]
P:0,Q:1 ,N: 0 Qn: 1 Pn:1 ,min:3 [1, 1] P:0,Q:1 ,N: 1 Qn: 1 Pn:0 ,min:3 [0, 1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
}
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
}
System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
" Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
P:2,Q:4 ,N: 0 Qn: 1 Pn:1 ,min:3 [0, 1, 1, 1, 1, 1, 2] P:2,Q:4 ,N: 1 Qn: 3 Pn:1 ,min:3 [1, 1, 1, 2, 3, 3, 3] P:0,Q:6 ,N: 0 Qn: 2 Pn:0 ,min:3 [0, 1, 1, 1, 1, 1, 2]
function result: [1, 2, 2]
P:0,Q:1 ,N: 0 Qn: 1 Pn:1 ,min:3 [1, 1] P:0,Q:1 ,N: 1 Qn: 1 Pn:0 ,min:3 [0, 1]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
// System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
// " Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
//System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
// System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
// " Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
//System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['AC', [0, 0, 1], [0, 1, 1]]
['AAGT', [0, 2, 2, 3], [0, 2, 3, 3]]
function result: [1, 1, 2]
function result: [1, 3, 3, 4]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 :
pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
// System.out.println("P:" + P + ",Q:"+ Q + " ,N: " + nucleotide +
// " Qn: "+qValue + " Pn:" + pValue + " ,min:" +minImpactFactor);
//System.out.println(java.util.Arrays.toString(mHolder[nucleotide].mOcurrencesSum));
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['TTTATTTT', [0, 0, 3, 4], [2, 3, 7, 7]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
// handling special cases when the less value is assigned on the P index
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 : pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['TTTATTTT', [0, 0, 3, 4], [2, 3, 7, 7]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
// handling special cases when the less value is assigned on the P index
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 : pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
['TTTATTTT', [0, 0, 3, 4], [2, 3, 7, 7]]
class Solution {
private ImpactFactorHolder[] mHolder;
private static final int A=0,C=1,G=2,T=3;
public int[] solution(String S, int[] P, int[] Q) {
mHolder = createImpactHolderArray(S);
int queriesLength = P.length;
int[] result = new int[queriesLength];
for (int i = 0; i < queriesLength; ++i ) {
int value = 0;
if( P[i] == Q[i]) {
value = lookupValueForIndex(S.charAt(P[i])) + 1;
} else {
value = calculateMinImpactFactor(P[i], Q[i]);
}
result[i] = value;
}
return result;
}
public int calculateMinImpactFactor(int P, int Q) {
int minImpactFactor = 3;
for (int nucleotide = A; nucleotide <= T; ++nucleotide ) {
int qValue = mHolder[nucleotide].mOcurrencesSum[Q];
int pValue = mHolder[nucleotide].mOcurrencesSum[P];
// handling special cases when the less value is assigned on the P index
if( P-1 >= 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P-1] == 0 ? 0 : pValue;
} else if ( P == 0 ) {
pValue = mHolder[nucleotide].mOcurrencesSum[P] == 1 ? 0 : pValue;
}
if ( qValue - pValue > 0) {
minImpactFactor = nucleotide;
break;
}
}
return minImpactFactor + 1;
}
public int lookupValueForIndex(char nucleotide) {
int value = 0;
switch (nucleotide) {
case 'A' :
value = A;
break;
case 'C' :
value = C;
break;
case 'G':
value = G;
break;
case 'T':
value = T;
break;
default:
break;
}
return value;
}
public ImpactFactorHolder[] createImpactHolderArray(String S) {
int length = S.length();
ImpactFactorHolder[] holder = new ImpactFactorHolder[4];
holder[A] = new ImpactFactorHolder(1,'A', length);
holder[C] = new ImpactFactorHolder(2,'C', length);
holder[G] = new ImpactFactorHolder(3,'G', length);
holder[T] = new ImpactFactorHolder(4,'T', length);
int i =0;
for(char c : S.toCharArray()) {
int nucleotide = lookupValueForIndex(c);
++holder[nucleotide].mAcum;
holder[nucleotide].mOcurrencesSum[i] = holder[nucleotide].mAcum;
holder[A].mOcurrencesSum[i] = holder[A].mAcum;
holder[C].mOcurrencesSum[i] = holder[C].mAcum;
holder[G].mOcurrencesSum[i] = holder[G].mAcum;
holder[T].mOcurrencesSum[i] = holder[T].mAcum;
++i;
}
return holder;
}
private static class ImpactFactorHolder {
public ImpactFactorHolder(int impactFactor, char nucleotide, int length) {
mImpactFactor = impactFactor;
mNucleotide = nucleotide;
mOcurrencesSum = new int[length];
mAcum = 0;
}
int mImpactFactor;
char mNucleotide;
int[] mOcurrencesSum;
int mAcum;
}
}
The solution obtained perfect score.