Skip to content

Latest commit

 

History

History
21 lines (16 loc) · 683 Bytes

File metadata and controls

21 lines (16 loc) · 683 Bytes

Problem 4: Tracking the Intruder

Problem Statement

In an array containing n + 1 integers where each integer is between 1 and n (inclusive), there is exactly one duplicate number. Find this duplicate number without modifying the array and using only constant extra space.

Input Format

  • An array of integers nums.

Output Format

  • An integer representing the duplicate value.

Constraints

  • 1 <= n <= 10^5
  • nums.length == n + 1
  • 1 <= nums[i] <= n
  • All the integers in nums appear only once except for one integer which appears two or more times.

Example

Input: nums = [1, 3, 4, 2, 2]
Output: 2
Explanation: 2 is the repeating integer.