title: Time complexity of the code below
body: <p>I am trying to check the time complexity of the below simple program.
  The program replaces spaces in a string with <code>'%20'</code>.</p>
  
  <ol>
  <li><p>The loop to count spaces (O(1) time)</p>
  
  <pre><code>    foreach (char k in s)
      {
          if (k == ' ')
          {
              spaces_cnt++;
          }
      }
  </code></pre></li>
  <li><p>The loop to replace the spaces (O(n) where n is size of string)</p>
  
  <pre><code>    char[] c = new char[s.Length + spaces_cnt * 3];
      int i = 0;
      int j = 0;
      while (i&lt;s.Length)
      {
          if (s[i] != ' ')
          {
              c[j] = s[i];
              j++;
              i++;
          }
          else
          {
  
              c[j] = '%';
              c[j + 1] = '2';
              c[j + 2] = '0';
              j = j + 3;
              i++;
          }
      }
  </code></pre></li>
  </ol>
  
  <p>So I am guessing it is a "O(n) + O(1)" solution. Please correct me if I am wrong.</p>