Minimum Deletions to Make Array Beautiful LeetCode solution in JavaScript
1var minDeletion = function (nums) {2const n = nums.length;3const res = [];45for (let i = 0; i < n; ++i) {6const num = nums[i];78if (res.length % 2 === 0 || res.at(-1) != num) {9res.push(num);10}11}1213if (res.length % 2 === 1) res.pop();1415return n - res.length;16};