title: Take into consideration Long Arrays/Strings
body: <p>I've been trying the challenges/Exercises of codility and I've come across a problem. When it tests Large Arrays/Strings my code always results in Timeout Errors. An example of this would be the following challenge:
  <em>&quot;GenomicRangeQuery&quot;</em></p>
  <p>A non-empty zero-indexed string S is given. String S consists of N characters from the set of upper-case English letters A, C, G, T.</p>
  <p>This string actually represents a DNA sequence, and the upper-case letters represent single nucleotides.</p>
  <p>You are also given non-empty zero-indexed arrays P and Q consisting of M integers. These arrays represent queries about minimal nucleotides. We represent the letters of string S as integers 1, 2, 3, 4 in arrays P and Q, where A = 1, C = 2, G = 3, T = 4, and we assume that A &lt; C &lt; G &lt; T.</p>
  <p>Query K requires you to find the minimal nucleotide from the range (P[K], Q[K]), 0 ≤ P[i] ≤ Q[i] &lt; N.</p>
  <p>For example, consider string S = GACACCATA and arrays P, Q such that:</p>
  <pre><code>P[0] = 0    Q[0] = 8
  P[1] = 0    Q[1] = 2
  P[2] = 4    Q[2] = 5
  P[3] = 7    Q[3] = 7
  </code></pre>
  <p>The minimal nucleotides from these ranges are as follows:</p>
  <pre><code>(0, 8) is A identified by 1,
  (0, 2) is A identified by 1,
  (4, 5) is C identified by 2,
  (7, 7) is T identified by 4.
  </code></pre>
  <p>Write a function:</p>
  <pre><code>class Solution { public int[] solution(String S, int[] P, int[] Q); } 
  </code></pre>
  <p>that, given a non-empty zero-indexed string S consisting of N characters and two non-empty zero-indexed arrays P and Q consisting of M integers, returns an array consisting of M characters specifying the consecutive answers to all queries.</p>
  <p>For example, given the string S = GACACCATA and arrays P, Q such that:</p>
  <pre><code>P[0] = 0    Q[0] = 8
  P[1] = 0    Q[1] = 2
  P[2] = 4    Q[2] = 5
  P[3] = 7    Q[3] = 7
  </code></pre>
  <p>the function should return the values [1, 1, 2, 4], as explained above.</p>
  <p>Assume that:</p>
  <pre><code>N is an integer within the range [1..100,000];
  M is an integer within the range [1..50,000];
  each element of array P, Q is an integer within the range [0..N − 1];
  P[i] ≤ Q[i];
  string S consists only of upper-case English letters A, C, G, T.
  </code></pre>
  <p>Below is the code I've come up with but unfortunately always gives me the Timeout Error when going against Large Arrays/Strings.
  If you have suggestions on how to improve or wipe out that error please don't hesitate! I'm always trying to think outside of the box and come up with solutions of my own but that error has been plaguing me for a while.</p>
  <pre><code>import java.util.Arrays;
  
  class Solution {
      public int[] solution(String S, int[] P, int[] Q) {
          // A impact = 1; C=2, G=3; T=4
          // S not empty
          // minimal impact
          String[] split;
          int[] stringToIntegers = new int[S.length()];
          int[] solution = new int[P.length];
  
          if(S.isEmpty()) return solution;
          if(P.length != Q.length) return solution;
          split = S.split(&quot;&quot;);
  
          for(int k=0;k&lt;split.length;k++){
              switch(split[k]){
                  case &quot;A&quot;:
                      stringToIntegers[k] = 1;
                      break;
                  case &quot;C&quot;:
                      stringToIntegers[k] = 2;
                       break;
                  case &quot;G&quot;:
                      stringToIntegers[k] = 3;
                      break;
                  case &quot;T&quot;:
                      stringToIntegers[k] = 4;
                      break;
              }
          }
          for(int i =0; i&lt;solution.length;i++){
                  solution[i] = LowestValue(stringToIntegers, P[i], Q[i]);
          }
          return solution;
      }
  
      public int LowestValue(int[] stringToIntegers, int pValue, int qValue){
          int minimalImpact = 4;
          for(int j = pValue; j &lt;= qValue; j++){
              if(stringToIntegers[j] &lt; minimalImpact){
                  minimalImpact = stringToIntegers[j];
              }
          }
          return minimalImpact;
      }
  }
  </code></pre>