longest commen prefix with constant memory