title: What will be time complexity for the given algorithm?
body: <p>We were given the problem for which I came up with a solution. Could somebody help me identify the time complexity for the given solution? Should it be O(n) or O(n^2)? According to me it should be O(n).</p>
  <p><strong>Problem</strong></p>
  <p>Write a program to print the sum of the elements of an array following the given
  below condition.</p>
  <p>If the array has 6 and 7 in succeeding orders, ignore the numbers between 6 and 7 and consider the other numbers for calculation of sum.</p>
  <p>Eg1) Array Elements - 10,3,6,1,2,7,9
  O/P: 22
  [i.e 10+3+9]</p>
  <p>Eg2) Array Elements - 7,1,2,3,6
  O/P:19</p>
  <p>Eg3) Array Elements - 1,6,4,7,9
  O/P:10</p>
  <p><strong>Solution</strong></p>
  <pre><code>outer: for (i = 0; i &lt; elementsCount; ++i) {
              if (arr[i] == 6) {
                  int sumBetweenBounds = arr[i];
  
                  for (j = i + 1; j &lt; elementsCount; ++j) {
                      if (arr[j] == 7) {
                          i = j;
                          continue outer;
                      }
  
                      sumBetweenBounds += arr[j];
                  }
  
                  sum += sumBetweenBounds;
                  continue;
              }
  
              sum += arr[i];
          }
  </code></pre>