can solve it in one traverse.