PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000237. Tìm số xuất hiện lặp lại (Find the Duplicate Number)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm số xuất hiện lặp lại (Find the Duplicate Number)
Find the Duplicate Number
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
An array contains integers in the inclusive range from 1 to . Exactly one distinct value occurs at least twice; every other value that occurs appears once. Identify the repeated value. The algorithm should leave the input array unchanged and use constant auxiliary space, excluding the array itself.
Input
The first line contains integer . The second line contains integers .
Output
Print the single repeated value.
Subtasks
- Subtask 1 (20 points): ; for all ; exactly one value has frequency at least 2, every other value has frequency at most 1.
- Subtask 2 (30 points): ; for all ; exactly one value occurs exactly twice, every other value has frequency at most 1.
- Subtask 3 (50 points): ; for all ; exactly one value has frequency at least 2, every other value has frequency at most 1.
Examples
Input
5
2 5 2 1 4 2
Output
2
Explanation
Value 2 occurs at positions 1, 3 and 6. Values 1, 4 and 5 occur once, and 3 is absent. The repeated value is 2.