Nearest neighbor problem