Maximize the profit in buying and selling of stocks