A Simple Algorithm for the Constrained Sequence Problems