title: Can my algorithm be considered as O(n)? "Finding the longest substring with unique characters"
body: <p>I stumbled upon this excercise: </p>
  
  <blockquote>
    <p>Create a function that returns the longest substring with unique
    characters. </p>
  </blockquote>
  
  <p>and I'm just wondering if I have accomplished O(n) time complexity with the solution I came up with.</p>
  
  <p>i.e: </p>
  
  <pre><code>getMaxSubStr("linkshortener") -&gt; "linkshorte"
  </code></pre>
  
  <p>there's only one for loop no nesting so this should be O(n) right, what's giving me doubts is that when tempStr stumbles a repeating character the iterator goes back to the string index of where the repeating character is last seen, so that adds to the runtime operations needed to be done and not sure if it's still O(n)</p>
  
  <pre><code>async function maxUniqueStr(string) {
    let maxStr = "";
    let tempStr = "";
    let lastSeen = {};
  
    for (let i = 0; i &lt; string.length; i++) {
      let char = string.charAt(i);
  
      if (tempStr.includes(char)) {
        i = lastSeen[char];
        tempStr = "";
        console.log("-continue-", i);
        continue;
      }
  
      tempStr += char;
      maxStr = tempStr.length &gt; maxStr.length ? tempStr : maxStr;
      lastSeen[char] = i;  
    }
  
    return maxStr;
  }
  </code></pre>