Problem 1
You will be given an arrayarr of sizen. Print "YES" if there is any duplicate value in the array, "NO" otherwise.
Sample Input 1
5
2 8 5 7 3
Sample Output 1
NO
Sample Input 2
7
2 1 3 5 2 1 9
Sample Output 2
YES
Input Format
- First line will containn.
- Second line will contain the arrayarr.
Follow the steps to resolve the problem:
- Assuming we get an input.
- Now declaren and input its value.
- Declare an array name isarr, and take that as input.
- Take atmp _to check if there are duplicate values in the array.[_tmp _is a variable used as a flag to indicate whether there are duplicate elements in the array. The name "_tmp" is often used as a shorthand for "temporary" or "temporary variable." Its purpose is to store a temporary state or result during the execution of the program.]
- Then loop through and look for duplicates. If duplicate value is found then I will set"tmp = 1" and also break the loop.
- After that I will check, if duplicate value is found I will print"YES", if not found I will print"NO".
Below is the implementation of the above method:
#include <bits/stdc++.h>using namespace std;int main(){ int n; cin >> n; int arr[n]; for (int i = 0; i < n; i++) cin >> arr[i]; int tmp = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (arr[i] == arr[j]) { tmp = 1; break; } } } if (tmp) cout << "YES" << endl; else cout << "NO" << endl; return 0;}
Top comments(4)

- Email
- LocationSan Francisco Bay Area
- EducationM.S., University of Illinois at Urbana-Champaign
- WorkRetired Principal Software Engineer
- Joined
Headers in thebits
directory arenot meant to be included by users directly. You should#include
the headers you need explicitly.

- LocationDhaka 1207, Bangladesh
- EducationDhaka Mohila Polytechnic Institute, Bangladesh
- WorkStudent
- Joined
#include <bits/stdc++.h>
is all in one. So I used it.
But why users cannot directly use it??

- Email
- LocationSan Francisco Bay Area
- EducationM.S., University of Illinois at Urbana-Champaign
- WorkRetired Principal Software Engineer
- Joined
It’s not standard. It’s specific to GNU. It’s not guaranteed to exist anywhere else.
That aside, having the compiler read and parse every single standard header file would greatly increase the compile time for non-trivial programs.

- LocationDhaka 1207, Bangladesh
- EducationDhaka Mohila Polytechnic Institute, Bangladesh
- WorkStudent
- Joined
Many thanks for the valuable information💛
For further actions, you may consider blocking this person and/orreporting abuse