Count Unique Substring Leetcode Javascript