Added the solution for stack2