Subset with repeat elements

Iterative solution