Subsequence Weighting Hackerrank Solution