firstOccurrence
and lastOccurrence
, of size 26 to store the first occurrence of each character in firstString
and the last occurrence in secondString
, respectively.firstString
from start to end, updating firstOccurrence
with the index of the first occurrence of each character.secondString
from end to start, updating lastOccurrence
with the index of the last occurrence of each character.minDifference
to a large value and count
to 0.firstString
and its last occurrence in secondString
.minDifference
, update minDifference
and reset count
to 1.minDifference
, increment count
.count
as the number of quadruples.