a bookends a word b if b both starts and ends with a. For example, "aba" bookends "ababa", while "ab" does not bookend "abc". Every word bookends itself.
Given the list words, return the number of index pairs i < j where words[i] bookends words[j].words=["ok", "okok", "o", "oko"] → 2
The pairs are "ok" with "okok" and "o" with "oko". "okok" is not framed by "o" because it ends in k.
words=["abcab", "ab"] → 0
The short word comes after the long one, and only pairs where the framing word comes first count.
words=["x", "x", "xx"] → 3
All three pairs count: "x"–"x", "x"–"xx", and the second "x"–"xx".
words=["ok", "okok", "o", "oko"]
2
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.