May 26, 2024
true if any value appears at least twice; otherwise, return false if all values are distinct.[1, 2, 3, 1] -> Output: true because 1 appears twice.true (duplicate found).false.# Initialize hash set
seen = set()
# Iterate through the array
for num in nums:
if num in seen:
return True
seen.add(num)
# If no duplicates found, return False
return False