A curious case of O(N^2) behavior which should be O(N) · GitHub