Add solution and tests for countSubstrings