Given an array of length N containing integers between 1
and N, determine if it contains any duplicates.
Answers were Sorted based on User's Feedback
Answer / ramkumar
What if the array is
1) 1,2,3,4,5
2) 1,2,2,5,5
both sums to 15!!
Is This Answer Correct ? | 8 Yes | 2 No |
Answer / sid
duplicate = False;
for (i =1; i <= N; i++)
{
a[a[i] % N] += N;
}
for (i =1; i <= N; i++)
{
if (a[i] / N >= 2)
{
duplicate = True;
}
}
return duplicate;
Is This Answer Correct ? | 14 Yes | 17 No |
Answer / ash
If the question is just to find just whether there are
duplicates in the array, we can just sum all the numbers
and if the sum is less than n(n+1)/2, some number in the
array has repeated.
Is This Answer Correct ? | 8 Yes | 39 No |
Why c++ is called c++ and not c+?
how to exchnage bits in a byte b7<-->b0 b6<-->b1 b5<-->b2 b4<-->b3 please mail me the code if any one know to rajeshmb4u@gmail.com
can u suggest me am in a confusion to choose whether to go to c programming or a software testing . am a graduate in B.sc(electronics).
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
how to execute a program using if else condition and the output should enter number and the number is odd only...
You have an array of n integers, randomly ordered with value 1 to n-1.The array is such that there is only one and one value occurred twice. How will you find this number?
What is double pointer?
how many header file is in C language ?
44 Answers College School Exams Tests, CTS, IBM, IMS, Infosys, ME, Sign Solutions, Wipro, XVT,
how to return 1000 variables from functio9n in c?plz give me code also
What is static memory allocation?
What is stack in c?
what is the difference between i++ and ++i?