Problem: Longest Substring Without Repeating Characters.
I have this solution. But I do not have much of theoretical knowledge about DSA. Trying to understand which algorithm it comes under and will it be efficient than 'Sliding Window' approach. Per my understanding the time complexity is o(n). What will be the space complexity? Any help/guidance will be appreciated. Thanks!
public class Solution {
public int LengthOfLongestSubstring(string s) {
List<char> list = new List<char>();
int output = 0;
foreach(char c in s)
{
if(list.Contains(c))
{
if(list.Count > output)
output=list.Count;
int index = list.IndexOf(c);
list.RemoveRange(0,index+1);
list.Add(c);
}
else
{
list.Add(c);
}
}
return list.Count > output ? list.Count : output;
}
}