1. If the code started with was *GPL'ed, each edit resulted in a GPL'ed piece of code, thus the final edit was a change to a GPL'd piece of code and the result is GPLed.
This is basically no different from doing the same with a proprietary library you'd licensed from a vendor.
Because you looked at the code to begin with you couldn't make the "clean room implementation" argument even if every line were different.
2. MIT or related licenses: just depends on whether what remains is "substantial".
* modulo the effect of interested lawyers, of course.