replace O(N²) with O(N) algorithm in roshambobot