v1 solution with Stack