From 1e078777e78a982dd8248c1a0a89604dc227d212 Mon Sep 17 00:00:00 2001 From: Gajay <6947656+GAjay@users.noreply.github.com> Date: Wed, 21 Oct 2026 01:30:42 +0000 Subject: [PATCH] feat(daily): implement 2026-10-21 contains-duplicate --- automation/state.json | 4 ++-- .../2026-10-21-contains-duplicate/README.md | 24 +++++++++++++++++++ .../contains-duplicate.test.js | 17 +++++++++++++ .../2026-10-21-contains-duplicate/solution.js | 12 ++++++++++ 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 problems/2026-10-21-contains-duplicate/README.md create mode 100644 problems/2026-10-21-contains-duplicate/contains-duplicate.test.js create mode 100644 problems/2026-10-21-contains-duplicate/solution.js diff --git a/automation/state.json b/automation/state.json index cdd93c1..b4dc476 100644 --- a/automation/state.json +++ b/automation/state.json @@ -1,4 +1,4 @@ { - "catalogIndex": 1, - "lastRunDate": "2026-10-20" + "catalogIndex": 2, + "lastRunDate": "2026-10-21" } diff --git a/problems/2026-10-21-contains-duplicate/README.md b/problems/2026-10-21-contains-duplicate/README.md new file mode 100644 index 0000000..ad57435 --- /dev/null +++ b/problems/2026-10-21-contains-duplicate/README.md @@ -0,0 +1,24 @@ +# Contains Duplicate + +## Problem + +Given an integer array `nums`, return `true` if any value appears **at least twice** in the array, and return `false` if every element is distinct. + +## Examples + +``` +Input: nums = [1, 2, 3, 1] +Output: true + +Input: nums = [1, 2, 3, 4] +Output: false +``` + +## Constraints + +- `1 <= nums.length <= 10^5` +- `-10^9 <= nums[i] <= 10^9` + +## Notes + +Implement `containsDuplicate` in `solution.js`. diff --git a/problems/2026-10-21-contains-duplicate/contains-duplicate.test.js b/problems/2026-10-21-contains-duplicate/contains-duplicate.test.js new file mode 100644 index 0000000..2855b40 --- /dev/null +++ b/problems/2026-10-21-contains-duplicate/contains-duplicate.test.js @@ -0,0 +1,17 @@ +import { describe, it } from "node:test"; +import assert from "node:assert/strict"; +import { containsDuplicate } from "./solution.js"; + +describe("containsDuplicate", () => { + it("has duplicate", () => { + assert.equal(containsDuplicate([1,2,3,1]), true); + }); + + it("all unique", () => { + assert.equal(containsDuplicate([1,2,3,4]), false); + }); + + it("duplicate at end", () => { + assert.equal(containsDuplicate([1,1]), true); + }); +}); diff --git a/problems/2026-10-21-contains-duplicate/solution.js b/problems/2026-10-21-contains-duplicate/solution.js new file mode 100644 index 0000000..2b805f1 --- /dev/null +++ b/problems/2026-10-21-contains-duplicate/solution.js @@ -0,0 +1,12 @@ +/** + * @param {number[]} nums + * @returns {boolean} + */ +export function containsDuplicate(nums) { + const seen = new Set(); + for (const n of nums) { + if (seen.has(n)) return true; + seen.add(n); + } + return false; +}