answer
to store the result.indices
to store lists of indices for each character in s1
.indices
with the positions of each character in s1
.ind
of size m
with zeros to track the current index for each character in s2
.start
from 0
to n - 1
.
prev
to start - 1
.j
from 0
to m - 1
.
curIndices
be indices[s2[j]]
.ind[j]
until curIndices[ind[j]] > prev
.ind[j]
equals the length of curIndices
, break and continue with the next start
.prev
to curIndices[ind[j]]
.answer
if it is empty or the current window is smaller.answer
.