Javascript | Simple Prefix Array Solution w/ Explanation (plus 2-Line Solution) | 97%/94%
First, we need to create a prefix array, pfx, of possible pair sums to store our changes. Then we iterate through the pairs in N and update pfx for the values a
First, we need to create a prefix array, **pfx**, of possible pair sums to store our changes. Then we iterate through the pairs in N and update **pfx** for the values at which the solution changes.\n\nLet\'s say that for every pair **[a,b]** we make **a** the larger of the two numbers. This means that we can achieve the target in 2 moves anywhere in our maximum range of **2** to **2*L**. 1-move solutions will range only from **1+b** to **a+L**. A 0-move solution only exists at **a+b**.\n\nWhen updating **pfx** with the changes in ascending order, we can note that the solution gets better (**+1**) at **1+b** and then **a+b**, then gets worse (**-1**) at **a+b+1** and then **a+L+1**. Since our target numbers don\'t start until **2** and there are a lot of **+1**s in those change point equations, we can simplify it a bit by shifting everything down one and using **a**, **a+b-1**, **a+b**, and **b+L** instead in order to be a bit more time and space efficient.\n\nSo now we can iterate through the pairs in **N** and then update the values in **pfx** with the relevant changes. Once that\'s done, we can **sum** through **pfx** and find the **best** value for moves saved. The max number of moves is the same as **len**, so we should just return **len - best**.\n\n```\nvar minMoves = function(N, L) {\n    let len = N.length, pfx = new Array(L * 2 + 1).fill(0), best = 0\n    for (let i = len / 2, a, b; i < len; i++) {\n        a = N[i], b = N[len-i-1]\n        if (b > a) [a,b] = [b,a]\n        pfx[b]++, pfx[a+b-1]++, pfx[a+b]--, pfx[a+L]--\n    }\n    for (let i = 1, sum = 0; i <= 2 * L; i++)\n        sum += pfx[i], best = sum > best ? sum : best\n    return len - best\n};\n```\n```\n\n```\n\n\n**Bonus**:\nHere\'s a moderately disgusting 2-line version of this solution:\n\n```\nlet minMoves=(N,L,n=N.length,r=Array(L*2+1).fill(0),i=n/2)=>{\n    for(;i-->0;)a=N[i],b=N[n-i-1],r[a>b?b:a]++,r[a+b-1]++,r[a+b]--,r[(a>b?a:b)+L]--\n    return n-r.reduce((a,b)=>(i+=b)>a?i:a)-1\n};\n```\n\nIf you can find a way to shorten this even further, feel free to drop a reply!
['JavaScript']