solve distinct subsequence