[Java] BFS check if a position can reach
Use BFS to find the shortest distance\n2. For each point, calculate the range it can reach\n3. Use TreeSet to find the point that can reach for the range [L : R
1. Use BFS to find the shortest distance\n2. For each point, calculate the range it can reach\n3. Use TreeSet to find the point that can reach for the range [L : R]\n\nNote : Do some experiement to find out how to calculate the range, it need to deal with both odd index and even index seperatly\n\n```\nclass Solution {\n    int INF = 1000000000;\n    public int[] minReverseOperations(int n, int s, int[] banned, int k) {\n        int d[] = new int[n];\n        Arrays.fill(d, INF);\n        boolean is[] = new boolean[n];\n        for(int i : banned) is[i] = true;\n        \n        TreeSet<Integer> odd = new TreeSet<>();\n        TreeSet<Integer> even = new TreeSet<>();\n        for(int i = 0; i < n; i++) {\n            if(!is[i] && i != s) {\n                if(i % 2 == 0) even.add(i);\n                else odd.add(i);\n            }\n        }\n\t\t\n        Queue<Integer> q = new LinkedList<>();\n        q.add(s);\n        d[s] = 0;\n        while(q.size() > 0) {\n            int u = q.poll();\n            int l = u;\n            int r = u;\n            \n            int ll = Math.max(0, u - k + 1);\n            int rr = ll + k - 1;\n            if(rr < n) {\n                int ith = u - ll;\n                l = ll + (k - ith - 1);\n            }\n            \n            int rrr = Math.min(n - 1, u + k - 1);\n            int lll = rrr - k + 1;\n            if(lll >= 0) {\n                int ith = u - lll;\n                r = lll + (k - ith - 1);\n            }\n            \n            \n            TreeSet<Integer> tree;\n         \n            if(u % 2 == 0) {\n                if(k % 2 == 0) tree = odd;\n                else tree = even;\n            } else {\n                if(k % 2 == 0) tree = even;\n                else tree = odd;\n            }\n            \n            while(true) {\n                Integer hi = tree.ceiling(l);\n                if(hi == null) break;\n\n                if(hi <= r) {\n                    d[hi] = d[u]  + 1;\n                    q.add(hi);\n                    tree.remove(hi);\n                } else {\n                    break;\n                }\n            }\n            \n            while(true) {\n                Integer lo = tree.floor(r);\n                if(lo == null) break;\n                if(lo >= l) {\n                    d[lo] = d[u] + 1;\n                    tree.remove(lo);\n                    q.add(lo);\n                } else {\n                    break;\n                }\n            }\n        }\n       \n        for(int i = 0; i < n; i++) {\n            if(d[i] == INF) d[i] = -1;\n        }\n        return d;\n    }\n}\n\n```
[]