That would depend on if the distribution was made within 90 days of electing to participate in making contributions.
Additionally, paying education expenses can waive the penalty tax on a distribution from an IRA but not from a 401(k).