Maybe should have started with the O(nk) version first...