[implementation] write code for longest common prefix