Find the Number or sub-string occurrences in string with first and last character being same. Interviewer mentioned to use some data structure type to optimize the approach apart from normal approach which i couldn't find anywhere later as well.
Sigiloso
We can use the sliding window algorithm with the size of 2 as you said the first and last characters should have to be there in the substring and an additional variable to track if we entered the substring in the traversing.