Reported September 2026
Capgeminihash table

Contains Duplicate

Reported by candidates from Capgemini's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Capgemini OA. Under 2s to a working solution.
Founder's read

Nums can hold 200000 integers, and that one constraint is the whole story of this Capgemini OA question, reported in September 2026. A nested loop checks about 20 billion pairs. It won't finish. Contains Duplicate is a hash-table problem, and you've probably seen it before. The danger isn't difficulty, it's overthinking it or fumbling the edge cases when the clock is running. If you blank on the live assessment, StealthCoder is the safety net running invisibly on your screen. But you shouldn't need it for this one. Here's the trick and the traps.

The problem

Return true when any integer appears at least twice in nums; otherwise return false.

Function
containsDuplicate(nums: int[]) → boolean

Examples
Example 1
nums = [1,2,3,1]
return = true
Case 1 exercises the documented deterministic contract.
Example 2
nums = [1,2,3,4]
return = false
Case 2 exercises the documented deterministic contract.
Example 3
nums = [1,1]
return = true
Case 3 exercises the documented deterministic contract.

Constraints
1 <= nums.length <= 200000.
-10^9 <= nums[i] <= 10^9.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Walk the array once and keep a hash set of values you've seen. For each number, check the set. If it's there, return true immediately. Otherwise add it and keep going. If the loop ends, return false. That's O(n) time and O(n) space. The sorting alternative is O(n log n) with O(1) extra space if you sort in place. Adjacent equal elements mean a duplicate. Both pass at 200000. The common pitfall is the brute-force double loop, which times out. Another is building the full set first and comparing its size to the array length. That works but doesn't exit early. Values go up to 10^9 in magnitude, so don't use a boolean array indexed by value. If the pattern slips your mind during the Capgemini OA, StealthCoder can hand you the set solution in seconds as a hedge. Know it cold anyway.

Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.

If this hits your live OA

You can drill Contains Duplicate cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as contains duplicate. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Capgemini's OA.

Capgemini reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Contains Duplicate FAQ

How hard is Capgemini's Contains Duplicate really?+

It's an easy problem. The only real test is whether you reach for a hash set instead of nested loops. With 200000 elements, brute force is too slow, so the constraint pushes you to the right answer. Write it in five lines and move on.

What's the trick to Contains Duplicate?+

Track seen values in a hash set as you scan. If the current number is already in the set, return true right away. If you finish the loop without a hit, return false. One pass, O(n) time, and it exits early on the first repeat.

Can I solve it without extra memory?+

Yes. Sort the array in place, then compare each element with its neighbor. Any equal adjacent pair means a duplicate. It costs O(n log n) time but only O(1) extra space, depending on the sort. The hash set is faster and simpler, so use it unless space is restricted.

Which edge cases should I check before submitting?+

Test a single element like [5], which must return false. Test [1,1], which must return true. Test negatives and values near 10^9 and -10^9. Don't index an array by value, since the range is huge. A hash set handles all of these without special casing.

How do I prepare for this in 48 hours?+

Write the hash set version from memory twice, then the sort version once. Say the complexity out loud for both. That covers it. Spend the remaining time on other hash-table patterns like two-sum and frequency counting, since the OA likely has more than one question.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Capgemini.

OA at Capgemini?
Invisible during screen share
Get it