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 is sprintf unsafe?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
Do you know pointer in c?
Explain how can type-insensitive macros be created?
main() { int x, arr[8]={11,22,33,44,55,66,77,88}; x=(arr+2)[3]; printf(ā%dā,x); }
what are the various memory handling mechanisms in C ?
a formula,a series of steps,or well defined set of rules for solving a problem a) algorithem b) program c) erdiagram d) compiler
What's wrong with "char *p; *p = malloc(10);"?
write a c program to find the square of a 5 digit number and print the result.
5 Answers Accenture, Sasken, Vimukti Technologies,
what is recursion in C
What does calloc stand for?
swap two integer variables without using a third temporary variable?