Longest Non-Repeating Substring Given a string as input find the longest contiguous substring that does not have any character twice or more.  If there are multiple such substrings you may output either.  You may assume that the input is on the printable ASCII range if you wish.

Scoring

Answers will first be ranked by the length of their own longest non-repeating substring, and then by their total length.  Lower scores will be better for both criteria.  Depending on the language this will probably feel like a code-golf challenge with a source restriction.

Triviality

In some languages achieving a score of 1, x (lenguage) or 2, x (Brain-flak and other turing tarpits) is pretty easy, however there are other languages in which minimizing the longest non-repeating substring is a challenge.  I had a lot of fun getting a score of 2 in Haskell, so I encourage you to seek out languages where this task is fun.

Test cases

"Good morning, Green orb!" -&gt; "ing, Gre"
"fffffffffff" -&gt; "f"
"oiiiiioiiii" -&gt; "io", "oi"
"1234567890"  -&gt; "1234567890"
"11122324455" -&gt; "324"


Scoring submission

You can score your programs using the following snippet:



input.addEventListener("input", change);

// note: intentionally verbose :)
function isUnique(str) {
  var maxCount = 0;
  var counts = {};
  for(var i = 0; i &lt; str.length; i++) {
    var c = str.charAt(i);
    counts[c] |= 0;
    counts[c]++;
    if(maxCount &lt; counts[c]) {
      maxCount = counts[c];
    }
  }
  return maxCount &lt;= 1;
}

function maximizeSubstring(str, pred, cost) {
  var mostExpensive = -1;
  // iterate over substrings
  function iterate(start, end) {
    var slice = str.slice(start, end);
    if(pred(slice)) {
      var profit = cost(slice);
      if(profit &gt; mostExpensive) {
        mostExpensive = profit;
      }
    }
    end++;
    if(start &gt;= str.length) {
      return;
    }
    else if(end &gt; str.length) {
      start++;
      iterate(start, start);
    }
    else {
      iterate(start, end);
    }
  }
  iterate(0, 0);
  return mostExpensive;
}

function size(x) {
  return x.length;
}

function longestNonRepeatingSize(str) {
  return maximizeSubstring(str, isUnique, size);
}

function change() {
  var code = input.value;
  output.value = "Your score is: " + longestNonRepeatingSize(code);
}

change();
* {
  font-family: monospace;
}
Input code here:
&lt;br&gt;
&lt;textarea id="input"&gt;&lt;/textarea&gt;
&lt;br&gt;
&lt;textarea id="output"&gt;&lt;/textarea&gt;
C, score 2,  747   720  662 bytes



L  [  1  &lt;&lt;  7  ]  ,  *  q  ,  *  r  ,  l  ,  d  ,  i  ,  c  ,  j  ,  s  ,  t  ,  k  =  1  &lt;&lt;  7  ;  h  (  )  {  q  =  s  +  i  +  j  ++  ;  *  q  %  k  &amp;&amp;  !  L  [  *  q  %  k  ]  ++  &amp;&amp;  h  (  ++  c  )  ;  }  g  (  )  {  q  =  s  +  i  ;  *  q  %  k  ?  z  (  k  )  ,  h  (  j  =  c  =  0  )  ,  c  &gt;  d  &amp;&amp;  (  d  =  c  )  &amp;&amp;  (  l  =  i  )  ,  g  (  ++  i  )  :  0  ;  }  f  (  S  ,  T  )  {  s  =  S  ;  l  =  i  =  d  =  0  ;  g  (  t  =  T  )  ;  p  (  i  =  0  )  ;  }  p  (  )  {  q  =  s  +  l  +  i  ;  r  =  t  +  i  ;  i  ++  &lt;  d  ?  p  (  *  r  =  *  q  )  :  (  *  r  =  0  )  ;  }  z  (  i  )  {  L  [  --  i  ]  =  0  ;  i  &amp;&amp;  z  (  i  )  ;  }


Works at least on 32-bit MinGW (with optimizations disabled). Doesn't use a single keyword.

Works apparently on TIO with gcc and clang, too: Try it online! (Thanks @Dennis!)

Call with:

int main()
{
    char str[1024];

    f("Good morning, Green orb!", str);
    puts(str);

    f("fffffffffff", str);
    puts(str);

    f("oiiiiioiiii", str);
    puts(str);

    f("1234567890", str);
    puts(str);

    f("L  [  1  &lt;&lt;  7  ]  ,  *  q  ,  *  r  ,  l  ,  d  ,  i  ,  c  ,  j  ,  s  ,  t  ,  k  =  1  &lt;&lt;  7  ;  h  (  )  {  q  =  s  +  i  +  j  ++  ;  *  q  %  k  &amp;&amp;  !  L  [  *  q  %  k  ]  ++  &amp;&amp;  h  (  ++  c  )  ;  }  g  (  )  {  q  =  s  +  i  ;  *  q  %  k  ?  z  (  k  )  ,  h  (  j  =  c  =  0  )  ,  c  &gt;  d  &amp;&amp;  (  d  =  c  )  &amp;&amp;  (  l  =  i  )  ,  g  (  ++  i  )  :  0  ;  }  f  (  S  ,  T  )  {  s  =  S  ;  l  =  i  =  d  =  0  ;  g  (  t  =  T  )  ;  p  (  i  =  0  )  ;  }  p  (  )  {  q  =  s  +  l  +  i  ;  r  =  t  +  i  ;  i  ++  &lt;  d  ?  p  (  *  r  =  *  q  )  :  (  *  r  =  0  )  ;  }  z  (  i  )  {  L  [  --  i  ]  =  0  ;  i  &amp;&amp;  z  (  i  )  ;  }");
    puts(str);
}


Output:



The code with slightly more readable formatting:

L[1&lt;&lt;7],
*q, *r, l, d, i, c, j, s, t, k=1&lt;&lt;7;

h()
{
    q = s+i+j++;
    *q%k &amp;&amp; !L[*q%k]++ &amp;&amp; h(++c);
}

g()
{
    q = s+i;
    *q%k ? z(k), h(j=c=0), c&gt;d &amp;&amp; (d=c) &amp;&amp; (l=i), g(++i) : 0;
}

f(S, T)
{
    s = S;
    l = i = d = 0;
    g(t=T);
    p(i=0);
}

p()
{
    q = s+l+i;
    r = t+i;
    i++&lt;d ? p(*r=*q) : (*r=0);
}

z(i)
{
    L[--i] = 0;
    i &amp;&amp; z(i);
}


And this can be used to generate proper spacing to get to the formatting with score 2: Try it online!



C, score 3, 309 bytes

i
,
j
,
l
,
c
,
d
;
f
(
\
c\
\
h\
\
a\
\
r
*
s
)
{
\
f\
\
o\
\
r
\
(
i
=
l
=
d
=
0
;
s
[
i
]
;
c
&gt;
d
&amp;&amp;
(
d
=
c
)
&amp;&amp;
(
l
=
i
)
,
++
i
)
\
f\
\
o\
\
r
(
\
c\
\
h\
\
a\
\
r

L
[
\
1\
\
2\
\
8
\
]
=
{
j
=
c
=
0
}
;
s
[
i
+
j
]
&amp;&amp;
!
L
[
s
[
i
+
j
++
]
]
++
;
++
c
)
;
\
w\
\
r\
\
i\
\
t\
\
e
(
1
,
s
+
l
,
d
)
;
}


Try it online!