SakeTami
Aditya Verma
Aditya Verma

patreon


Longest Substring With K Unique Characters

Video will be uploaded tomorrow evening, due to some technical difficulty cant upload now.

Comments

class Solution: def lengthOfLongestSubstringKDistinct(self, s: str, k: int) -> int: i=j=0 global_longest=0 tracker={} a=list(s) while j < len(a): curr_tracker_len=len(tracker) if curr_tracker_len < k: if a[j] in tracker.keys(): tracker[a[j]]=tracker[a[j]] + 1 else: tracker[a[j]]=1 elif curr_tracker_len > k: while len(tracker) > k: counter= tracker[a[i]]-1 if counter==0: del tracker[a[i]] else: tracker[a[i]]=counter i+=1 else: global_longest=max(global_longest,j-i+1) j+=1 return global_longest https://leetcode.com/problems/longest-substring-with-at-most-k-distinct-characters/ it's not working for "eceba" input

aarjay singh

please share the java code as well.

Seema Kumari


More Creators