FastPrepContains Duplicate
Problems/Contains Duplicate

Contains Duplicate

Microsoft logoMicrosoft● EasyINTERNONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: This was one of three interviews in a row for a Microsoft software engineering internship, each mixing behavioral and technical parts. The review does not say which one. A review lists the Contains Duplicate problem by name only, with no input or rules.

Here the input is an integer array of 1 to 10^4 values between -10^9 and 10^9, and you return true when some value occurs at least twice, false otherwise.

Our version is about 95% the same as the reported question.

Given an integer array nums, return true if some value appears at least twice, and false if every element is different.

Function

containsDuplicate(nums: int[]) → boolean

Examples

Example 1

nums = [1,5,3,5]return = true

The value 5 appears at index 1 and at index 3, so the answer is true.

Example 2

nums = [4,2,7]return = false

All three values are different, so the answer is false.

Example 3

nums = [8]return = false

A single element cannot repeat, so the answer is false.

Constraints

  • 1 <= nums.length <= 10^4
  • -10^9 <= nums[i] <= 10^9

More Microsoft Onsite Interview questions

  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
  • Totals from a Tiered Rate TableONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Map and Accumulate Learning QueriesPalantir · ONSITE INTERVIEWPalantir interview questions
  • Rank Transform an ArrayAgoda · ONSITE INTERVIEWAgoda interview questions
  • Deduplicate Logs: Keep FirstGoogle · ONSITE INTERVIEWGoogle interview questions
  • Loyal Customers by Two-Day Product VarietyAmazon · ONSITE INTERVIEW
  • Restaurant Vote LeadersZipRecruiter · PHONE SCREEN · ONSITE INTERVIEWZipRecruiter interview questions
  • High-Severity Counts by Search TypeChainalysis · ONSITE INTERVIEWChainalysis interview questions
  • Intersection of Two ListsJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
  • Pair Left and Right Socks by IDRoblox · ONSITE INTERVIEWRoblox interview questions
  • Net Position Calculation from API SnapshotsHeadlands Technologies · ONSITE INTERVIEWHeadlands Technologies interview questions
  • Count Word FrequenciesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions

Interview reports that mention this question

  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
  • Microsoft SWE Intern Interviews: 244 Experiences (Part 1 of 6)

Microsoft interview experiences

  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Late 2025: 47 Experiences (Part 3 of 6)
  • Microsoft SWE Intern, Early 2026: 54 Experiences (Part 2 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public boolean containsDuplicate(int[] nums) {
        // Write your code here.
    }
}
Checking account…