From d3c15f3b09f226f68e27db784f8db46030bb2c75 Mon Sep 17 00:00:00 2001 From: Jainsuhani2021 <104892962+Jainsuhani2021@users.noreply.github.com> Date: Tue, 25 Oct 2022 23:10:23 +0530 Subject: [PATCH] Create Find Duplicate In this we have to return the duplicate number in the array. Array list contains numbers from 0 to N-2 where N is size of array. So we have done the sum of natural numbers and subtract it from sum of array elements. --- common_ds_algo_problems/Find Duplicate | 36 ++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 common_ds_algo_problems/Find Duplicate diff --git a/common_ds_algo_problems/Find Duplicate b/common_ds_algo_problems/Find Duplicate new file mode 100644 index 0000000..d15b27e --- /dev/null +++ b/common_ds_algo_problems/Find Duplicate @@ -0,0 +1,36 @@ +#include +using namespace std; +int duplicateNumber(int *arr, int size) +{ + int i; + int newsum=((size-2)*(size-1))/2; //n(n+1)/2 sum of n natural no. + int sum=0; + for(i=0;i> t; + + while (t--) + { + int size; + cin >> size; + int *input = new int[size]; + + for (int i = 0; i < size; i++) + { + cin >> input[i]; + } + + cout << duplicateNumber(input, size) << endl; + } + + return 0; +}