Count Prefix and Suffix Pairs I | Leetcode 3042