functionfirstDuplicateValue(arr) {constmemo=newSet();for (let i =0; i <arr.length; i++) {constnum= arr[i];if (memo.has(num)) return arr[i];memo.add(num); }return-1;}// Do not edit the line below.exports.firstDuplicateValue = firstDuplicateValue;
N, 1
functionfirstDuplicateValue(arr) {for (let i =0; i <arr.length; i++) {constnum=Math.abs(arr[i]);if (arr[num -1] <0) return num; arr[num -1] = arr[num -1] *-1; }return-1;}// Do not edit the line below.exports.firstDuplicateValue = firstDuplicateValue;