Beats 100% users || JS || Easy solution
\n\n# Code\n\n/**\n* @param {number} n\n* @param {number} p\n* @param {number[]} banned\n* @param {number} k\n* @return {number[]}\n*/\nfunction minReverseOpera
\n![image.png](https://assets.leetcode.com/users/images/bbad7754-5cdc-4761-952f-70537609c8ce_1713474845.391348.png)\n# Code\n```\n/**\n* @param {number} n\n* @param {number} p\n* @param {number[]} banned\n* @param {number} k\n* @return {number[]}\n*/\nfunction minReverseOperations(n, p, banned, k) {\n\t\t\tconst ans = Array(n).fill(-1);\n\n\t\t\tfor (const b of banned) {\n\t\t\t\tans[b] = -2;\n\t\t\t}\n\n\t\t\tlet queue = [p];\n\t\t\tans[p] = 0;\n\t\t\t--k;\n\n\t\t\tdo {\n\t\t\t\tlet excludeFrom = -1, excludeTo = -1;\n\n\t\t\t\tconst distance = ans[queue[0]] + 1;\n\t\t\t\tconst newQueue = [];\n\n\t\t\t\tfor (const q of queue) {\n\t\t\t\t\tlet start = q - k;\n\t\t\t\t\tlet end = q + k;\n\n\t\t\t\t\tif (start < 0) {\n\t\t\t\t\t\tstart = k - q;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (end >= n) {\n\t\t\t\t\t\tend = 2 * (n - 1) - q - k;\n\t\t\t\t\t}\n\n\t\t\t\t\tfor (let i = start; i <= end; i += 2) {\n\t\t\t\t\t\tif (i >= excludeFrom && i <= excludeTo) {\n\t\t\t\t\t\t\ti = excludeTo;\n\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (ans[i] === -1) {\n\t\t\t\t\t\t\tans[i] = distance;\n\t\t\t\t\t\t\tnewQueue.push(i);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!(excludeTo < start || excludeFrom > end)) {\n\t\t\t\t\t\texcludeFrom = start < excludeFrom ? start : excludeFrom;\n\t\t\t\t\t\texcludeTo = end > excludeTo ? end : excludeTo;\n\t\t\t\t\t} else {\n\t\t\t\t\t\texcludeFrom = start;\n\t\t\t\t\t\texcludeTo = end;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tqueue = newQueue.sort((a, b) => a - b);\n\t\t\t} while (queue.length)\n\n\t\t\tfor (let i = 0; i < n; ++i) {\n\t\t\t\tans[i] = ans[i] < -1 ? -1 : ans[i];\n\t\t\t}\n\n\t\t\treturn ans;\n\t\t}\n```
['JavaScript']