private boolean existImpl(char[][] board, String word, int idx, int x, int y, Set<List<Integer>> set) {
        if (idx == word.length()) {
            return true;
        }
        boolean find = false;
        int[][] neighbours = {
                {x - 1, y},
                {x + 1, y},
                {x, y - 1},
                {x, y + 1}
        };
        char c = word.charAt(idx);
        for (int i = 0; i != neighbours.length; i++) {
            int px = neighbours[i][0], py = neighbours[i][1];
            if (set.contains(Arrays.asList(px, py))) {
                continue;
            }
            if (px < 0 || px >= board.length || py < 0 || py >= board[0].length) {
                continue;
            }
            if (board[px][py] == c) {
                set.add(Arrays.asList(x, y));
                find = existImpl(board, word, idx + 1, px, py, set);
            }
            if (find) {
                break;
            } else {
                set.remove(Arrays.asList(x, y));
            }
        }
        return find;
    }