Given a string S, find the length of the longest substring with all distinct characters. 
Example 1:
Input:
S = "geeksforgeeks"
Output: 7
Explanation: "eksforg" is the longest 
substring with all distinct characters.
Example 2:
Input: 
S = "aaa"
Output: 1
Explanation: "a" is the longest substring 
with all distinct characters.
Your Task:
You don't need to read input or print anything. Your task is to complete the function longestSubstrDitinctChars() which takes the string S as input and returns the length of the longest substring with all distinct characters.
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(K), where K is Constant.
Constraints:
1<=|S|<=10^{5}

Difficulty: EASY
Tags: String algorithms

Data structures
Skill types: Data structures
Expected Time Complexity: O(|S|).
Expected Auxiliary Space: O(K), where K is Constant.

Starter code:
#User function Template for python3

class Solution:

    def longestSubstrDistinctChars(self, S):
        # code here

Solutions:
class Solution:

	def longestSubstrDistinctChars(self, string):
		seen = {}
		maximum_length = 0
		start = 0
		for end in range(len(string)):
			if string[end] in seen:
				start = max(start, seen[string[end]] + 1)
			seen[string[end]] = end
			maximum_length = max(maximum_length, end - start + 1)
		return maximum_length


class Solution:

	def longestSubstrDistinctChars(self, s):
		(i, j, k) = (0, 0, 0)
		for i in range(len(s) + 1):
			if len(s[j:i]) == len(set(s[j:i])):
				k = max(len(s[j:i]), k)
			else:
				while len(s[j:i]) != len(set(s[j:i])) and j < i:
					j += 1
					k = max(len(s[j:i]), k)
		k = max(len(s[j:i]), k)
		return k


class Solution:

	def longestSubstrDistinctChars(self, str):
		n = len(str)
		res = 0
		for i in range(n):
			visited = [0] * 256
			for j in range(i, n):
				if visited[ord(str[j])] == True:
					break
				else:
					res = max(res, j - i + 1)
					visited[ord(str[j])] = True
			visited[ord(str[i])] = False
		return res


class Solution:

	def longestSubstrDistinctChars(self, S):
		i = 0
		j = 0
		ans = []
		l = []
		while j < len(S):
			if S[j] not in l:
				l.append(S[j])
				j += 1
			else:
				l = []
				res = i + 1
				i += 1
				j = res
			ans.append(j - i)
		return max(ans)


class Solution:

	def longestSubstrDistinctChars(self, S):
		long_len = 0
		st = 0
		dct = {}
		for i in range(len(S)):
			if S[i] in dct:
				st = max(st, dct[S[i]] + 1)
			dct[S[i]] = i
			long_len = max(long_len, i - st + 1)
		return long_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		visited = {}
		maxLen = 0
		start = 0
		for i in range(len(S)):
			if S[i] in visited:
				start = max(start, visited[S[i]] + 1)
			maxLen = max(maxLen, i - start + 1)
			visited[S[i]] = i
		return maxLen


class Solution:

	def longestSubstrDistinctChars(self, str):
		if len(S) == 0:
			return 0
		elif len(S) == 1:
			return 1
		else:
			maxLength = -1
			final = ''
			for i in range(0, len(S)):
				char = S[i]
				if S[i] in final:
					final = final[final.index(S[i]) + 1:]
				final = final + S[i]
				maxLength = max(len(final), maxLength)
			return maxLength
		test = ''


class Solution:

	def longestSubstrDistinctChars(self, str):
		test = ''
		maxLength = -1
		if len(str) == 0:
			return 0
		elif len(str) == 1:
			return 1
		for c in list(str):
			current = ''.join(c)
			if current in test:
				test = test[test.index(current) + 1:]
			test = test + ''.join(c)
			maxLength = max(len(test), maxLength)
		return maxLength


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		max_len = 0
		start = 0
		seen = {}
		for end in range(n):
			if S[end] in seen and start <= seen[S[end]]:
				start = seen[S[end]] + 1
			else:
				max_len = max(max_len, end - start + 1)
			seen[S[end]] = end
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		char = set()
		l = 0
		c = 0
		for r in range(len(S)):
			while S[r] in char:
				char.remove(S[l])
				l += 1
			char.add(S[r])
			c = max(c, len(char))
		return c


class Solution:

	def longestSubstrDistinctChars(self, s):
		last_index = {}
		max_len = 0
		start_index = 0
		for i in range(len(s)):
			if s[i] in last_index:
				start_index = max(start_index, last_index[s[i]] + 1)
			max_len = max(max_len, i - start_index + 1)
			last_index[s[i]] = i
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, s):
		n = len(s)
		mx = -1
		(i, j) = (0, 0)
		d = {}
		t = ''
		while i < n and j < n:
			if s[j] in d:
				d = {}
				mx = max(mx, len(t))
				t = ''
				i += 1
				j = i
			else:
				t += s[j]
				d[s[j]] = 1
				j += 1
		return max(len(t), mx)


class Solution:

	def longestSubstrDistinctChars(self, S):
		s = ''
		d = {}
		m = 0
		l = []
		for i in range(len(S)):
			s = ''
			for j in range(i, len(S)):
				if S[j] not in d:
					s += S[j]
					d[S[j]] = 1
				else:
					break
			if len(s) > m:
				m = len(s)
			d = {}
		return m


class Solution:

	def longestSubstrDistinctChars(self, s):
		letters = set()
		l = 0
		res = 0
		for i in range(len(s)):
			while s[i] in letters:
				letters.remove(s[l])
				l += 1
			letters.add(s[i])
			res = max(res, i - l + 1)
		return res


class Solution:

	def longestSubstrDistinctChars(self, S):
		t = {}
		m = ''
		l = []
		i = 0
		while i < len(S):
			if S[i] not in t:
				t[S[i]] = i
				m = m + S[i]
				i = i + 1
			else:
				l.append(len(m))
				i = t[S[i]] + 1
				t = {}
				m = ''
		if m != '':
			l.append(len(m))
		k = max(l)
		return k


class Solution:

	def longestSubstrDistinctChars(self, S):
		m = 0
		for i in range(len(S)):
			c = 0
			l = []
			for j in range(i, len(S)):
				if S[j] in l:
					break
				else:
					l.append(S[j])
					c += 1
			m = max(m, c)
		return m


class Solution:

	def longestSubstrDistinctChars(self, S):
		lst = [0] * 26
		l = 0
		r = 0
		sub = ''
		lth = 0
		curr = 0
		for i in range(len(S)):
			x = ord(S[i]) - 97
			if lst[x] != 0:
				while lst[x] != 0:
					lst[ord(S[l]) - 97] = 0
					l += 1
					curr -= 1
			sub += chr(x + 97)
			lst[x] += 1
			r += 1
			curr += 1
			if curr > lth:
				lth = curr
		return lth


class Solution:

	def longestSubstrDistinctChars(self, S):
		c = 0
		maxlen = 0
		st = []
		for i in range(len(S)):
			if S[i] not in st:
				st.append(S[i])
				c += 1
				if c > maxlen:
					maxlen = c
			else:
				while st.pop(0) != S[i]:
					continue
				st.append(S[i])
				c = len(st)
				if c > maxlen:
					maxlen = c
		return maxlen


class Solution:

	def longestSubstrDistinctChars(self, S):
		d = {}
		m = 0
		i = 0
		for j in range(len(S)):
			if S[j] not in d:
				d[S[j]] = j
			else:
				if len(d) > m:
					m = len(d)
				i = d[S[j]] + 1
				d1 = d.copy()
				for k in d:
					if d1[k] < i:
						del d1[k]
				d = d1
				d[S[j]] = j
		if m < len(d):
			return len(d)
		return m


class Solution:

	def longestSubstrDistinctChars(self, S):
		setStr = set()
		l = 0
		res = 0
		for i in range(len(S)):
			while S[i] in setStr:
				setStr.remove(S[l])
				l += 1
			setStr.add(S[i])
			res = max(res, i - l + 1)
		return res


class Solution:

	def longestSubstrDistinctChars(self, S):
		char_set = set()
		left = 0
		max_len = 0
		for right in range(len(S)):
			while S[right] in char_set:
				char_set.remove(S[left])
				left += 1
			char_set.add(S[right])
			max_len = max(max_len, right - left + 1)
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, s):
		i = 0
		j = 0
		k = 1
		maxi = 0
		n = len(s)
		while k < n and j < n:
			if s[k] in s[i:j + 1]:
				i += 1
				j = i
				k = i + 1
			else:
				j += 1
				k += 1
			length = len(s[i:j + 1])
			maxi = max(maxi, length)
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		chars = set()
		i = j = max_len = 0
		while i < n and j < n:
			if S[j] not in chars:
				chars.add(S[j])
				j += 1
				max_len = max(max_len, j - i)
			else:
				chars.remove(S[i])
				i += 1
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		charSet = set()
		l = 0
		res = 0
		for r in range(len(S)):
			while S[r] in charSet:
				charSet.remove(S[l])
				l += 1
			charSet.add(S[r])
			res = max(res, r - l + 1)
		return res


class Solution:

	def longestSubstrDistinctChars(self, S):
		l = ''
		maxL = -1
		if len(S) == 0:
			return 0
		elif len(S) == 1:
			return 1
		for c in list(S):
			curr = ''.join(c)
			if curr in l:
				l = l[l.index(curr) + 1:]
			l = l + ''.join(c)
			maxL = max(len(l), maxL)
		return maxL


class Solution:

	def longestSubstrDistinctChars(self, S):
		max_len_substr = 0
		substrin = []
		for i in range(len(S)):
			if S[i] in substrin:
				ind = substrin.index(S[i])
				max_len_substr = max(max_len_substr, len(substrin))
				substrin = substrin[ind + 1:]
				substrin.append(S[i])
			else:
				substrin.append(S[i])
		return max(max_len_substr, len(substrin))


class Solution:

	def longestSubstrDistinctChars(self, S):
		dic = {}
		maxi = 0
		start = 0
		for i in range(len(S)):
			if S[i] not in dic:
				dic[S[i]] = i
			else:
				if dic[S[i]] != -1:
					while start < dic[S[i]] + 1:
						dic[start] = -1
						start += 1
				dic[S[i]] = i
			maxi = max(maxi, i - start + 1)
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, s):
		n = len(s)
		chars = set()
		start = end = max_len = 0
		while end < n:
			if s[end] not in chars:
				chars.add(s[end])
				end += 1
				max_len = max(max_len, end - start)
			else:
				chars.remove(s[start])
				start += 1
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		maxi = 0
		l = []
		for i in S:
			while i in l:
				l.remove(l[0])
			l.append(i)
			if maxi < len(l):
				maxi = len(l)
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, S):
		sett = set()
		result = 0
		(leftPtr, rightPtr) = (0, 0)
		for rightPtr in range(len(S)):
			while S[rightPtr] in sett:
				sett.remove(S[leftPtr])
				leftPtr += 1
			sett.add(S[rightPtr])
			result = max(result, len(sett))
		return result


class Solution:

	def longestSubstrDistinctChars(self, S):
		l = []
		d = {}
		start = 0
		r = ''
		m = 0
		i = 0
		while i < len(S):
			if S[i] not in d:
				d[S[i]] = 1
				r = r + S[i]
				m += 1
				i += 1
			else:
				l.append(m)
				j = r.index(S[i])
				i = start + j + 1
				start = i
				r = ''
				m = 0
				d = {}
		l.append(m)
		if l == []:
			return m
		return max(l)


class Solution:

	def longestSubstrDistinctChars(self, s):
		d = {}
		ws = 0
		n = len(s)
		ans = 0
		for we in range(n):
			while s[we] in d:
				d[s[ws]] -= 1
				if d[s[ws]] == 0:
					del d[s[ws]]
				ws += 1
			d[s[we]] = 1
			ans = max(ans, we - ws + 1)
		return ans


class Solution:

	def longestSubstrDistinctChars(self, S):
		hashmap = {}
		left = 0
		right = 0
		i = -1
		j = -1
		max_len = -int(1000000000.0)
		while right < len(S):
			if S[right] not in hashmap:
				hashmap[S[right]] = 1
			else:
				while left <= right and S[right] in hashmap and (hashmap[S[right]] == 1):
					hashmap[S[left]] -= 1
					if hashmap[S[left]] == 0:
						del hashmap[S[left]]
					left += 1
				hashmap[S[right]] = 1
			if i == -1 and j == -1:
				i = left
				j = right
			elif j - i < right - left:
				i = left
				j = right
			max_len = max(max_len, j - i + 1)
			right += 1
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		(window_start, max_len, last_char_index_map) = (0, 0, {})
		for window_end in range(len(S)):
			if S[window_end] in last_char_index_map:
				window_start = max(window_start, last_char_index_map[S[window_end]] + 1)
			last_char_index_map[S[window_end]] = window_end
			max_len = max(max_len, window_end - window_start + 1)
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		dict1 = {}
		l = 0
		size = 0
		j = 0
		for i in range(len(S)):
			if S[i] in dict1:
				while S[i] in dict1:
					del dict1[S[j]]
					j += 1
					size -= 1
				dict1[S[i]] = 1
				size += 1
			else:
				dict1[S[i]] = 1
				size += 1
				if size > l:
					l = size
		return l


class Solution:

	def longestSubstrDistinctChars(self, S):
		windowStart = 0
		maxCount = 0
		hashSet = set()
		for i in range(len(S)):
			while S[i] in hashSet:
				hashSet.remove(S[windowStart])
				windowStart += 1
			hashSet.add(S[i])
			maxCount = max(maxCount, i - windowStart + 1)
		return maxCount


class Solution:

	def check(self, ar, i, j):
		dic = {}
		while j < len(ar):
			if ar[j] not in dic:
				dic[ar[j]] = 1
			else:
				break
			j += 1
		return len(dic)

	def longestSubstrDistinctChars(self, S):
		i = 0
		ar = list(S)
		ans = 0
		while i < len(S):
			k = self.check(ar, i, i)
			ans = max(k, ans)
			i += 1
		return ans


class Solution:

	def longestSubstrDistinctChars(self, S):
		start = end = max_len = 0
		char_dict = {}
		for (i, c) in enumerate(S):
			if c in char_dict and char_dict[c] >= start:
				max_len = max(max_len, end - start)
				start = char_dict[c] + 1
			char_dict[c] = i
			end += 1
		return max(max_len, end - start)


class Solution:

	def longestSubstrDistinctChars(self, S):
		(a, maxa, i) = ('', '', 0)
		while i < len(S):
			if S[i] not in a:
				a += S[i]
				if len(a) >= len(maxa):
					maxa = a
			else:
				if len(a) >= len(maxa):
					maxa = a
				if i > 0 and S[i - 1] == S[i]:
					a = S[i]
				else:
					l = -1
					s = []
					r = a.index(S[i])
					for _ in range(S.count(a)):
						l = S.index(a, l + 1)
						s.append(l)
					if len(s) > 1:
						s = [j for j in s if j < i]
					i = r + s[-1]
					a = ''
			i += 1
		return len(maxa)


class Solution:

	def longestSubstrDistinctChars(self, S):
		left = 0
		res = 0
		cur = set()
		for right in range(len(S)):
			while S[right] in cur:
				cur.remove(S[left])
				left += 1
			cur.add(S[right])
			res = max(res, right - left + 1)
		return res


def isValid(arr, i):
	seen = {}
	while i < len(arr):
		if arr[i] not in seen:
			seen[arr[i]] = 1
		else:
			break
		i += 1
	return len(seen)

class Solution:

	def longestSubstrDistinctChars(self, arr):
		i = 0
		ans = 0
		while i < len(arr):
			k = isValid(arr, i)
			ans = max(k, ans)
			i += 1
		return ans


class Solution:

	def longestSubstrDistinctChars(self, s):
		(l, ml, i, n) = (0, 0, 0, len(s))
		while i < n - l:
			l = 0
			alfa = {}
			for j in range(i, n):
				if s[j] in alfa:
					ml = max(l, ml)
					break
				else:
					alfa.update({s[j]: j})
					l += 1
			i = alfa[s[j]] + 1
		return max(ml, l)


class Solution:

	def longestSubstrDistinctChars(self, S):
		s = ''
		m1 = -1
		if len(S) == 0:
			return 0
		elif len(S) == 1:
			return 1
		for i in list(S):
			ans = ''.join(i)
			if ans in s:
				s = s[s.index(ans) + 1:]
			s += ''.join(i)
			m1 = max(len(s), m1)
		return m1


class Solution:

	def longestSubstrDistinctChars(self, S):
		a = []
		maxm = 0
		if len(S) == 1:
			return 1
		for i in S:
			if i not in a:
				a.append(i)
			else:
				if maxm < len(a):
					maxm = len(a)
				c = a.index(i)
				a = a[c + 1:]
				a.append(i)
		if maxm < len(a):
			return len(a)
		return maxm


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		if n == 0:
			return 0
		longest_substring = ''
		current_substring = ''
		for i in range(n):
			if S[i] not in current_substring:
				current_substring += S[i]
				if len(current_substring) > len(longest_substring):
					longest_substring = current_substring
			else:
				current_substring = current_substring[current_substring.index(S[i]) + 1:] + S[i]
		return len(longest_substring)


class Solution:

	def longestSubstrDistinctChars(self, S):
		st = 0
		occ = {}
		max_len = 0
		for i in range(0, len(S)):
			if S[i] in occ.keys():
				st = max(st, occ[S[i]] + 1)
			occ[S[i]] = i
			max_len = max(max_len, i - st + 1)
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		(i, j, k, max_ln, n) = (0, 0, 1, 0, len(S))
		while k < n and j < n:
			if S[k] in S[i:j + 1]:
				i += 1
				(j, k) = (i, i + 1)
			else:
				j += 1
				k += 1
			length = len(S[i:j + 1])
			max_ln = max(max_ln, length)
		return max_ln


class Solution:

	def longestSubstrDistinctChars(self, S):
		(l, l1) = ([], [])
		s1 = ''
		for i in range(len(S)):
			s1 = S[i]
			for j in range(i + 1, len(S)):
				if S[j] not in s1:
					if S[j] != S[i]:
						s1 += S[j]
					else:
						break
				else:
					break
			l.append(s1)
			continue
		for i in l:
			l1.append(len(i))
		return max(l1)


class Solution:

	def longestSubstrDistinctChars(self, S):
		(i, j, ans, n) = (0, 0, 0, len(S))
		mp = dict()
		while j < n:
			while S[j] in mp:
				mp.pop(S[i])
				i += 1
			if S[j] not in mp:
				mp[S[j]] = 1
			ans = max(ans, j - i + 1)
			j += 1
		return ans


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		start = 0
		end = 0
		max_length = 0
		char_set = set()
		while end < n:
			if S[end] not in char_set:
				char_set.add(S[end])
				end += 1
				max_length = max(max_length, end - start)
			else:
				char_set.remove(S[start])
				start += 1
		return max_length


class Solution:

	def longestSubstrDistinctChars(self, S):
		(i, j) = (0, 0)
		s = set()
		n = len(S)
		maxi = 0
		while j < n:
			while S[j] in s:
				s.remove(S[i])
				i += 1
			s.add(S[j])
			maxi = max(maxi, j - i + 1)
			j += 1
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, s):
		mp = {}
		(i, j) = (0, 0)
		(count, ans) = (0, -1)
		while j < len(s):
			count += 1
			if s[j] in mp:
				mp[s[j]] += 1
			else:
				mp[s[j]] = 1
			if len(mp) == j - i + 1:
				ans = max(ans, count)
				j += 1
			elif len(mp) < j - i + 1:
				while len(mp) < j - i + 1:
					mp[s[i]] -= 1
					count -= 1
					if mp[s[i]] == 0:
						del mp[s[i]]
					i += 1
				j += 1
		return ans


from collections import defaultdict

class Solution:

	def longestSubstrDistinctChars(self, S):
		freq = defaultdict(lambda : 0)
		l = r = 0
		m = 0
		while r < len(S):
			freq[S[r]] += 1
			while r < len(S) and freq[S[r]] > 1:
				freq[S[l]] -= 1
				l += 1
			m = max(m, r - l + 1)
			r += 1
		return m


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		if len(S) == 0:
			return 0
		left = 0
		right = 0
		maxlen = 0
		l = set()
		while right < n:
			if S[right] not in l:
				l.add(S[right])
				right = right + 1
				maxlen = max(maxlen, len(l))
			else:
				l.remove(S[left])
				left = left + 1
		return maxlen


class Solution:

	def longestSubstrDistinctChars(self, S):
		left = 0
		n = len(S)
		maxLength = 0
		dic = dict()
		for right in range(n):
			if S[right] in dic and dic[S[right]] >= left:
				left = dic[S[right]] + 1
			dic[S[right]] = right
			maxLength = max(maxLength, right - left + 1)
		return maxLength


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		max_len = 0
		left = 0
		char_dict = {}
		for right in range(n):
			if S[right] in char_dict and char_dict[S[right]] >= left:
				left = char_dict[S[right]] + 1
			char_dict[S[right]] = right
			max_len = max(max_len, right - left + 1)
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		res = 0
		m = 0
		x = [i for i in S]
		d = {}
		for i in range(len(x)):
			if x[i] in d:
				res = max(d[x[i]] + 1, res)
			m = max(m, i - res + 1)
			d[x[i]] = i
		return m


class Solution:

	def longestSubstrDistinctChars(self, s):
		max_length = 0
		for i in range(len(s)):
			seen = set()
			for j in range(i, len(s)):
				if s[j] in seen:
					break
				else:
					seen.add(s[j])
					max_length = max(max_length, len(seen))
		return max_length


class Solution:

	def longestSubstrDistinctChars(self, S):
		test = ''
		maxlen = -1
		if len(S) == 0:
			return 0
		if len(S) == 1:
			return 1
		for i in list(S):
			current = ''.join(i)
			if current in test:
				test = test[test.index(i) + 1:]
			test = test + ''.join(i)
			maxlen = max(len(test), maxlen)
		return maxlen


class Solution:

	def longestSubstrDistinctChars(self, s):
		n = len(s)
		dic = {}
		ans = 0
		i = j = 0
		while j < n:
			if s[j] not in dic:
				dic[s[j]] = j
			else:
				ans = max(ans, j - i)
				while s[j] in dic:
					del dic[s[i]]
					i += 1
				dic[s[j]] = j
			j += 1
		if j == n and s[j - 1] in dic:
			ans = max(ans, j - i)
		return ans


class Solution:

	def longestSubstrDistinctChars(self, s):
		i = 0
		temp = ''
		n = len(s)
		maxi = 0
		d = {}
		while i < n:
			if s[i] not in temp:
				temp += s[i]
				i += 1
			else:
				maxi = max(maxi, len(temp))
				temp = ''
				i = d[s[i]] + 1
			d[s[i - 1]] = i - 1
		else:
			maxi = max(maxi, len(temp))
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, s):
		i = 0
		j = 0
		k = 1
		m = 0
		n = len(S)
		while k < n and j < n:
			if s[k] in s[i:j + 1]:
				i += 1
				j = i
				k = i + 1
			else:
				j += 1
				k += 1
			l = len(S[i:j + 1])
			m = max(m, l)
		return m


class Solution:

	def longestSubstrDistinctChars(self, S):
		d = ''
		temp = ''
		for i in S:
			if i not in temp:
				temp += i
			else:
				if len(d) < len(temp):
					d = temp
				j = temp.find(i)
				temp = temp[j + 1:] + i
		if len(d) < len(temp):
			return len(temp)
		return len(d)


class Solution:

	def longestSubstrDistinctChars(self, S):
		vla = {}
		mx = 0
		st = 0
		i = 0
		while i < len(S):
			if S[i] not in vla:
				vla[S[i]] = i
				i += 1
			else:
				mx = max(mx, i - st)
				st = vla[S[i]] + 1
				vla.clear()
				i = st
		if i >= len(S) - 1:
			return max(mx, i - st)
		return mx


class Solution:

	def longestSubstrDistinctChars(self, S):
		ans = 0
		curr = ''
		for i in S:
			if i not in curr:
				curr += i
			else:
				ans = max(len(curr), ans)
				curr = curr[curr.index(i) + 1:] + i
		return max(len(curr), ans)


import math

class Solution:

	def longestSubstrDistinctChars(self, s):
		maxi = -math.inf
		(i, j) = (0, 0)
		dicti = {}
		n = len(s)
		while j < n:
			if s[j] not in dicti:
				dicti[s[j]] = 1
			else:
				dicti[s[j]] += 1
			if len(dicti) < j - i + 1:
				while len(dicti) < j - i + 1:
					if s[i] in dicti:
						dicti[s[i]] -= 1
						if dicti[s[i]] == 0:
							del dicti[s[i]]
					i += 1
				j += 1
			elif len(dicti) == j - i + 1:
				maxi = max(maxi, j - i + 1)
				j += 1
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, S):
		a = [-1] * 256
		start = -1
		ans = 0
		for i in range(0, len(S)):
			if a[ord(S[i]) - ord('a')] > start:
				start = a[ord(S[i]) - ord('a')]
			a[ord(S[i]) - ord('a')] = i
			ans = max(ans, i - start)
		return ans


class Solution:

	def longestSubstrDistinctChars(self, S):
		ans = 0
		n = len(S)
		for i in range(0, n):
			tem = ''
			c = 0
			for j in range(i, n):
				if S[j] in tem:
					ans = max(ans, c)
					break
				else:
					c = c + 1
					tem = tem + S[j]
			ans = max(ans, c)
		return ans


class Solution:

	def longestSubstrDistinctChars(self, S):
		w = set()
		maxLen = 0
		l = 0
		for r in range(len(S)):
			while S[r] in w:
				w.remove(S[l])
				l += 1
			maxLen = max(maxLen, r - l + 1)
			w.add(S[r])
		return maxLen


class Solution:

	def longestSubstrDistinctChars(self, S):
		last_idx = {}
		max_len = 0
		start_idx = 0
		for i in range(0, len(S)):
			if S[i] in last_idx:
				start_idx = max(start_idx, last_idx[S[i]] + 1)
			max_len = max(max_len, i - start_idx + 1)
			last_idx[S[i]] = i
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		n = len(S)
		last = {}
		max_len = 0
		start = 0
		for i in range(0, n):
			if S[i] in last:
				start = max(start, last[S[i]] + 1)
			max_len = max(max_len, i - start + 1)
			last[S[i]] = i
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, s):
		max_length = 0
		start = 0
		d = {}
		for i in range(len(s)):
			if s[i] in d:
				while start < i:
					if s[start] == s[i]:
						del d[s[start]]
						start += 1
						break
					else:
						del d[s[start]]
						start += 1
			d[s[i]] = d.get(s[i], 0) + 1
			max_length = max(max_length, i - start + 1)
		return max_length


class Solution:

	def longestSubstrDistinctChars(self, S):
		f = {}
		start = 0
		end = 0
		maxlen = 0
		n = len(S)
		while end < n:
			f[S[end]] = f.get(S[end], 0) + 1
			if len(f) == end - start + 1:
				maxlen = max(maxlen, end - start + 1)
			else:
				while len(f) != end - start + 1:
					f[S[start]] -= 1
					if f[S[start]] == 0:
						f.pop(S[start])
					start += 1
			end += 1
		return maxlen


class Solution:

	def longestSubstrDistinctChars(self, S):
		if not S:
			return 0
		max_len = 0
		start = 0
		char_map = {}
		for i in range(len(S)):
			if S[i] in char_map and char_map[S[i]] >= start:
				start = char_map[S[i]] + 1
			else:
				max_len = max(max_len, i - start + 1)
			char_map[S[i]] = i
		return max_len


class Solution:

	def longestSubstrDistinctChars(self, S):
		if len(S) == 0:
			return 0
		n = len(S)
		s = set()
		s.add(S[0])
		leng = 1
		Max_Len = 0
		i = 1
		while i < n:
			if S[i] != S[i - 1] and S[i] not in s:
				s.add(S[i])
				leng += 1
				i += 1
				if leng > Max_Len:
					Max_Len = leng
			elif leng == 1:
				i += 1
			else:
				s.clear()
				i = i - leng + 1
				leng = 0
		return max(Max_Len, leng)


class Solution:

	def longestSubstrDistinctChars(self, S):
		dict1 = {}
		count = 1
		maxi = 1
		for k in S:
			if k not in dict1.keys():
				dict1[k] = 1
		dict1 = dict.fromkeys(dict1, 0)
		for i in range(len(S)):
			dict1[S[i]] = 1
			j = i + 1
			while j < len(S):
				if dict1[S[j]] == 1:
					dict1 = dict.fromkeys(dict1, 0)
					count = 1
					break
				else:
					dict1[S[j]] = 1
					count += 1
					maxi = max(maxi, count)
				j += 1
		return maxi


class Solution:

	def longestSubstrDistinctChars(self, S):
		s = ''
		a = []
		for i in range(len(S)):
			if s == '':
				s += S[i]
			for j in range(i + 1, len(S)):
				if S[j] in s:
					a.append(s)
					s = ''
					break
				else:
					s += S[j]
		return len(max(a, key=len))