accepted solution use stacks to do it..