SetAI-assisted round
Detect a duplicate in a list
Given a list of values, return true if any value appears more than once, and false if every value is unique. The list can be very large.
AIThe assistant proposed this solution
“I compare every pair of elements. If any two match, there's a duplicate. This is straightforward and doesn't need any extra data structures, so it's memory-efficient.”
1function containsDuplicate(nums) {
2 for (let i = 0; i < nums.length; i++) {
3 for (let j = i + 1; j < nums.length; j++) {
4 if (nums[i] === nums[j]) return true;
5 }
6 }
7 return false;
8}
Before you accept this, make the call. What's your verdict?