Contains Duplicate
Read the lesson → understand the pattern → then code. Tutor works offline (built-in teacher); optional Cursor/Gemini keys upgrade chat quality.
Topic refresher: Arrays — Index Thinking
Treat every array problem as: What do I know at index i? What must I remember from the past?
// Running best pattern
int best = nums[0];
for (int i = 1; i < n; i++) {
// update state using nums[i]
best = max(best, candidate);
}
return best;EasyArraysLeetCode #217
Contains Duplicate
Return true if any value appears at least twice.
Pattern
Set membership. If insert fails / already exists → duplicate.
Sorting also works (O(n log n)) but the set is the interview answer.
Examples
Example 1
Input
4 1 2 3 1
Output
true
Example 2
Input
4 1 2 3 4
Output
false
Stuck? Take a nudge
C++17Autosaves