Memory beats 100% [EXPLAINED]
Intuition\nThe goal is to group k consecutive 1s in the array using the minimum number of adjacent swaps. Since swapping affects the position of 1s, the key is 
# Intuition\nThe goal is to group k consecutive 1s in the array using the minimum number of adjacent swaps. Since swapping affects the position of 1s, the key is to find an optimal way to align them closer together, minimizing movement.\n\n# Approach\nIdentify the positions of all 1s, then use a sliding window technique to calculate the cost of moving k 1s together, adjusting the cost as you slide the window across the array.\n\n# Complexity\n- Time complexity:\nO(n), where n is the length of the array, because we iterate through the array a couple of times.\n\n- Space complexity:\nO(k), as we store the positions of 1s, which can be at most k if there are k 1s in the array.\n\n# Code\n```typescript []\n/**\n * Calculate the minimum number of adjacent swaps needed to get k consecutive 1\'s.\n * \n * @param {number[]} nums - An array consisting of 0\'s and 1\'s.\n * @param {number} k - The number of consecutive 1\'s desired.\n * @return {number} - The minimum number of adjacent swaps needed.\n */\nfunction minMoves(nums: number[], k: number): number {\n    // If k is 1, no swaps are needed as we already have single 1\'s.\n    if (k === 1) return 0;\n\n    // h is the half-point for k (used for centering the 1\'s)\n    let h = (k + 1) >> 1;\n    let n = nums.length; // Length of the input array\n\n    let l = 0; // Left pointer for the current window of k 1\'s\n    let r = 0; // Right pointer for the current window of k 1\'s\n    let m = 0; // Midpoint of the current window of k 1\'s\n\n    let cnt = 0; // Counter for the number of 1\'s encountered\n    // Find the first `k` 1\'s in the array\n    for (; r < n; ++r) {\n        if (nums[r]) {\n            ++cnt;\n            // Set the left pointer when the first 1 is found\n            if (cnt === 1) l = r;\n            // Set the midpoint when we reach h 1\'s\n            if (cnt === h) m = r;\n            // Break when we have counted k 1\'s\n            if (cnt === k) break;\n        }\n    }\n\n    // Calculate the initial cost to align the first k 1\'s\n    let cur = h * (1 - h); // Initial move cost\n    // If k is even, adjust the cost\n    if (!(k & 1)) cur -= h;\n\n    // Calculate the initial cost for the current window\n    for (let i = l; i <= r; ++i) {\n        if (nums[i]) cur += Math.abs(i - m);\n    }\n\n    let res = cur; // Store the result\n\n    // Move to the next position and start sliding the window\n    ++r;\n    for (; r < n; ++r) {\n        if (nums[r]) {\n            // Adjust the current cost as we slide the window\n            if (k & 1) cur -= m - l; // If k is odd, adjust based on the midpoint\n            do ++m; while (!nums[m]); // Move midpoint to the next 1\n            if (!(k & 1)) cur -= m - l; // If k is even, adjust again\n            do ++l; while (!nums[l]); // Move left pointer to the next 1\n            cur += r - m; // Update current cost based on the new right pointer\n\n            // Update the result if the current cost is less\n            res = Math.min(cur, res);\n            // If no moves are needed, return 0 early\n            if (!res) return 0;\n        }\n    }\n\n    return res; // Return the minimum moves required\n}\n\n```
['TypeScript']