Loading problem…
You're building a validation system for an e-commerce cart or form submission. You need to check if a user has duplicate items in their cart or if there are duplicate IDs in a form submission.
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.
containsDuplicate([1,2,3,1]); // true - 1 appears twice
containsDuplicate([1,2,3,4]); // false - all distinct
containsDuplicate([1,1,1,3,3,4,3,2,4,2]); // true - multiple duplicatesThis problem models real validation scenarios: