countBookendSubstrings 🌶️🌶️🌶️
A substring is a bookend when its first and last characters are the same letter. A single letter counts (it is both its own first and last character). Substrings are counted by where they sit, so the two a letters in "aba" each give their own one-letter bookend.
Write a method countBookendSubstrings that takes a String s and returns the number of bookend substrings in it.
For example, in "aba" the bookends are "a", "b", "a" and "aba", so countBookendSubstrings("aba") is 4. And countBookendSubstrings("abc") is 3.
A substring is fixed by where it starts and where it ends. Two loops can pick the start
i and the end j.The end
j can be the same place as the start (a one-letter substring), so the inner loop starts at i. Compare the letter at i with the letter at j.