title: Time Complexity (Terminated due to timeout 2s at Hackerrank)
body: <p><strong>Suggest some ways to reduce the time complexity of this following code.</strong></p>
  
  <p>The problem is:</p>
  
  <p><a href="https://i.stack.imgur.com/O6Epi.png" rel="nofollow noreferrer">This is question</a><br>
  <a href="https://i.stack.imgur.com/n7xMt.png" rel="nofollow noreferrer">This is sample input output</a><br>
  This code is working fine except two cases (terminated due to time limit 2s)</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;string.h&gt;
  int main()
      {
          unsigned char str[1000000];
          unsigned long int l;
          int i,j,t,k,c=0;
          scanf("%d",&amp;t);
          for(k=0;k&lt;t;k++)
          {
              c=0;
              scanf("%lu",&amp;l);
              scanf("%s",str);
              for(i=0;i&lt;l-1;i++)
              {
                  for(j=i+1;j&lt;l;j++)
                      if(str[i]=='S' &amp;&amp; str[j]=='A')
                          c++;
              }
              printf("%d\n",c);
          }
          return 0;
      }
  </code></pre>