Continue learning
Practice related DSA questions in the same topic.
Return the greatest length of a contiguous lowercase-letter sequence with no repeated letter.
Return the greatest length of a contiguous lowercase-letter sequence with no repeated letter.
def solve(values, target): last = [0] * (26) left = 0 right = 0 best = 0 while (right < len(values)): key = values[right] left = max(left, last[key]) best = max(best, ((right - left) + 1)) last[key] = (right + 1) right = (right + 1) return bestExclude the previous occurrence when it lies inside this window.
Exclude the previous occurrence when it lies inside this window.
Seat guests in a continuous row while admitting each badge colour only once.
Use each letter’s previous position to move the left boundary just beyond a conflicting occurrence.
O(n + 26) time · O(26) auxiliary space
Worked example · {"values":[0,1,2,0,1,3],"target":0} ⇒ 4
Edge case 1 · {"values":[],"target":0} ⇒ 0
Edge case 2 · {"values":[0,0],"target":0} ⇒ 1
The left boundary must never move backwards to a stale occurrence.
What changes for arbitrary Unicode input?