subsequence problem with nlogn time-complexity