Infosys interview question

solve the subsequence varient problem.