EASY JAVA SOLUTION
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n\n    public int maxMoves(int kx, int ky, int[][] positions) {\n        HashMap<List<Integer>, Integer> map = new HashMap<>();\n        for (int i = 0; i < positions.length; i++) {\n            map.put(List.of(positions[i][0], positions[i][1]), i);\n        }\n        int[][] d = new int[positions.length + 1][positions.length + 1];\n        maxMoves(List.of(kx, ky), map, d[positions.length]);\n        for (int i = 0; i < positions.length; i++) {\n            maxMoves(List.of(positions[i][0], positions[i][1]), map, d[i]);\n        }\n        return maxMoves(positions.length, 0, d, true, new int[positions.length + 1][1 << positions.length]);\n    }\n\n    private void maxMoves(List<Integer> list, HashMap<List<Integer>, Integer> map, int[] d) {\n        ArrayDeque<List<Integer>> deque = new ArrayDeque<>(List.of(list));\n        HashSet<List<Integer>> set = new HashSet<>();\n        for (int i = 0, c = d.length; c > 1; i++) {\n            for (int j = deque.size(); j > 0; j--) {\n                List<Integer> poll = deque.poll();\n                if (!set.contains(poll)) {\n                    set.add(poll);\n                    if (map.containsKey(poll)) {\n                        d[map.get(poll)] = i;\n                        c--;\n                    }\n                    if (poll.get(0) >= 0 && poll.get(0) < 50 && poll.get(1) >= 0 && poll.get(1) < 50) {\n                        for (int[] k : new int[][] { { -2, -1 }, { -2, 1 }, { -1, -2 }, { -1, 2 }, { 1, -2 }, { 1, 2 }, { 2, -1 }, { 2, 1 } }) {\n                            deque.offer(List.of(poll.get(0) + k[0], poll.get(1) + k[1]));\n                        }\n                    }\n                }\n            }\n        }\n    }\n\n    private int maxMoves(int k, int curr, int[][] d, boolean flag, int[][] dp) {\n        if (curr + 1 == 1 << d.length - 1) {\n            return 0;\n        } else if (dp[k][curr] == 0) {\n            dp[k][curr] = flag ? 0 : Integer.MAX_VALUE;\n            for (int i = 0; i < d.length - 1; i++) {\n                if ((1 << i & curr) == 0) {\n                    int next = maxMoves(i, 1 << i | curr, d, !flag, dp) + d[k][i];\n                    dp[k][curr] = flag ? Math.max(dp[k][curr], next) : Math.min(dp[k][curr], next);\n                }\n            }\n        }\n        return dp[k][curr];\n    }\n}\n```
['Java']