Length of longest substring without repeating chars in "toolliyo".
| Test | Status | Details |
|---|
Ready — edit the code above and click Run or Submit.
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
string s = "toolliyo";
var seen = new Dictionary<char, int>();
int best = 0, start = 0;
for (int j = 0; j < s.Length; j++) {
if (seen.ContainsKey(s[j]) && seen[s[j]] >= start) start = seen[s[j]] + 1;
seen[s[j]] = j;
best = Math.Max(best, j - start + 1);
}
Console.WriteLine(best);
}
}
Try solving on your own first, then reveal the official answer.
Sliding window with hash map.