title: Longest unique substring
body: <p>This question may seem repeated but I am posting it since I was not able to find the solution that I wanted.
  If the input string is "abcaadafghae", I want the first longest unique substring (without repeated characters) which should be "dafgh". I got the below program for finding the length of this substring which is 5, but I want the substring itself as the output.</p>
  
  <p>Thanks in advance.</p>
  
  <pre><code>int lengthOfLongestSubstring(string s) {
    int n = s.length();
    int i = 0, j = 0;
    int maxLen = 0;
    bool exist[256] = { false };
    while (j &lt; n) {
      if (exist[s[j]]) {
        maxLen = max(maxLen, j-i);
        while (s[i] != s[j]) {
          exist[s[i]] = false;
          i++;
        }
        i++;
        j++;
      } else {
        exist[s[j]] = true;
        j++;
      }
    }
    maxLen = max(maxLen, n-i);
    return maxLen;
  }
  </code></pre>