String Balancing using Stacks