Count Distinct Substrings Leetcode Javascript