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 does everyone say not to use gets?
What is the difference between strcpy() and memcpy() function in c programming?
what is the return type of printf
How do you convert a decimal number to its hexa-decimal equivalent.Give a C code to do the same
When should the const modifier be used?
What is pointers in c?
#include<stdio.h> #include<conio.h> void main() { int m=0111,n=20; printf("%d%d\n",m,n); getch(); }
What are the key features of C?
how to display 2-D array elements in spiral
what is compiler
What is the difference between new and malloc functions?
What is a file descriptor in c?