Contains Duplicate
Updated
Problem statement
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[]) → booleanExamples
Example 1
nums = [1,5,3,5]return = trueThe value 5 appears at index 1 and at index 3, so the answer is true.
Example 2
nums = [4,2,7]return = falseAll three values are different, so the answer is false.
Example 3
nums = [8]return = falseA 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