TITLE:-
Duplicate in array
PROBLEM:-
Line 1 : Size of input array
Line 2 : Array elements (separated by space)
Duplicate element
9
0 7 2 5 4 7 1 3 6
7
SOLUTION:-
#include <iostream>
using namespace std;
// arr - input array
// size - size of array
int DuplicateNumber(int arr[], int size){
/* Don't write main().
* Don't read input, it is passed as function argument.
* Return output and don't print it.
* Taking input and printing output is handled automatically.
*/
int sum=0;
for(int i=0;i<size;i++)
{
sum+=arr[i];
}
int sumnatural=((size-1)*(size-2))/2;
int duplicate=sum-sumnatural;
return duplicate;
}
int main() {
int size;
cin >> size;
int *input = new int[1 + size];
for(int i = 0; i < size; i++)
cin >> input[i];
cout << DuplicateNumber(input, size);
delete [] input;
return 0;
}
This is dummy text. It is not meant to be read. Accordingly, it is difficult to figure out when to end it. But then, this is dummy text. It is not meant to be read. Period.
If you have any doubts then please let me know... ConversionConversion EmoticonEmoticon