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 |
x=2,y=6,z=6 x=y==z; printf(%d",x)
13 Answers Bharat, Cisco, HCL, TCS,
How do you do dynamic memory allocation in C applications?
What are the disadvantages of c language?
What is extern keyword in c?
main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); } wat is the o/p and how?
The number of bytes of storage occupied by short, int and long are a) 2, 2 and 4 b) 2, 4 and 4 c) 4, 4 and 4 d) none
what is the diference between pointer to the function and function to the pointer?
Switch (i) i=1; case 1 i++; case 2 ++i; break; case 3 --i; Output of i after executing the program
There are 3 baskets of fruits with worng lables,one basket has apple,another basket has orange,another has combination of apple and orange,what is the least way of interchange the lables.
15 Answers Cisco, Google, MBT,
What are the key features of C?
How are variables declared in c?
What are the types of arrays in c?