Track the best valid bounds05.05
When a valid window beats bestLen, save bestL and bestR (and the new length). The answer slice is a[bestL..bestR], not just a number.
Window constraint: longest window with all unique values. Update bounds at the same moment you update bestLen. Ties keep the first bounds.
Same skill, three traces. Read all three before you try it.
01first best - given
s = "abca"- walk
abc at
L=0R=2length3→ save (0,2)bca at
L=1R=3length3ties, keep (0,2)- result
bestL=0bestR=2·"abc"
02array best - given
a = [4, 1, 9, 1]- walk
[4,1,9]at (0,2) length3→ save (0,2)[9,1]at (2,3) length2loses- result
bestL=0bestR=2·[4, 1, 9]
03single cell - given
a = [7]- walk
(
0,0) length1beats init0save
bestL=0bestR=0- result
bestL=0bestR=0·[7]
bestUniqueBounds(a).a is an array of integers, or s is a string. bestL and bestR are the saved bounds of the longest unique window, which includes a[bestL..bestR]. Ties keep the first.Return those bounds.
On
s="abca"; a=[4, 1, 9, 1]; a=[7].constraintsa (or s) is nonempty.
- Minimum Size Subarray Sum0/3 skills ready · sliding window · mediumopen
- Minimum Size Subarray Sum0/3 skills ready · sliding window · mediumopen
Every Check with Awel is frozen here. Open one to read the code or load it back into the editor.