Detect Whether Any Integer Value Repeats

Quick Overview

Detect any repeated integer by tracking prior values, with explicit expected-time and storage bounds.

Detect Whether Any Integer Value Repeats

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Return true if any integer value appears at least twice in nums. Return false when all values are distinct. Repeated positions need not be adjacent. ```cpp bool containsDuplicate(vector<int>& nums); ``` ### Examples ```text Input: nums = [8,-1,3,8] Output: true ``` ```text Input: nums = [0,4,-2] Output: false ``` ### Constraints - Length is between 1 and 100000. - Values lie between -1000000000 and 1000000000.

Overview: Detect any repeated integer by tracking prior values, with explicit expected-time and storage bounds.

Google logo
Google
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return true if any integer value appears at least twice in nums. Return false when all values are distinct. Repeated positions need not be adjacent.

bool containsDuplicate(vector<int>& nums);

Examples

Input: nums = [8,-1,3,8]
Output: true
Input: nums = [0,4,-2]
Output: false

Constraints

  • Length is between 1 and 100000.
  • Values lie between -1000000000 and 1000000000.