get_next in O(n^2)