Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'''
Given a string S, find the length of its longest substring that does not have any repeating characters.

Example 1:

Input:
S = geeksforgeeks
Output: 7
Explanation: The longest substring
without repeated characters is "ksforge".
Example 2:

Input:
S = abbcdb
Output: 3
Explanation: The longest substring is
"bcd". Here "abcd" is not a substring
of the given string.
'''


def SubsequenceLength(s):
v={}
l=0
maxlen=0
for i in range(len(s)):
if s[i] in v and l<=v[s[i]]:
l=v[s[i]]+1
else:
maxlen=max(maxlen,i-l+1)
v[s[i]]=i
return maxlen