Count Distinct Substring Leetcode Javascript