educative.io

C# solution for the same , if any one is intersted

public class LongestNoRepeatSubstring
{
//my solution
public static int GetLongestSubstring(string source)
{
int start = 0;
int end = 0;
int maxlength = 0;
HashSet longsubstr = new HashSet();

		//Time : O(n)
		//Space:

		while ((start <= source.Length - 1) && end <= (source.Length - 1))
		{
			//we will keep on adding to the set , if its not present in set.
			if (!longsubstr.Contains(source[end]))
			{
				longsubstr.Add(source[end]);
				maxlength = Math.Max(maxlength, (end - start) + 1);
				end++;
			}
			else
			{
				//if present in set 
				start = end;
				longsubstr.Clear();
				longsubstr.Add(source[end]);
				end++;
			}
		}
		return maxlength;
	}
}

Thanks! Looks good.