Java Sliding window median
```\nclass Solution {\n    public int minMoves(int[] nums, int k) {\n        List list  = new ArrayList(nums.length);\n        \n        for(int i = 0; i < nums
```\nclass Solution {\n    public int minMoves(int[] nums, int k) {\n        List<Integer> list  = new ArrayList<Integer>(nums.length);\n        \n        for(int i = 0; i < nums.length ;i++){\n            if(nums[i] == 1)\n            list.add(i);    \n        }\n        \n        int mid  = (k)/2;\n        int sum  = 0;\n        int ans  = 0;\n        int cmid = mid; // current mid\n        int lval =0, rval=0; // left value and right value\n    \n        //calculate first time\n        for(int i = 0; i < k; i++){\n            if(i <= mid){\n                lval += Math.abs(list.get(cmid) - list.get(i)) - Math.abs(cmid-i);\n            }\n            else{\n                rval += Math.abs(list.get(cmid) - list.get(i)) - Math.abs(cmid-i);   \n            }\n        }\n        \n        ans = lval + rval;\n      \n        int rcount = k%2 == 1? mid : mid -1;\n        \n        //use sliding window and move current mid\n        for(int i = k; i <list.size() ; i++){\n         int nextDiff =  Math.abs(list.get(cmid)-list.get(cmid+1));\n         lval -=  Math.abs(list.get(cmid) - list.get(i-k));\n         lval += nextDiff * (mid);\n         rval -= nextDiff * rcount;\n         rval +=  Math.abs(list.get(i)-list.get(cmid+1));\n         cmid++;\n         ans = Math.min(ans, lval+rval);\n        }\n        \n        return ans;\n    }\n}\n// 0 0 1 1
[]