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



Given an array of length N containing integers between 1 and N, determine if it contains any dupli..

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

Given an array of length N containing integers between 1 and N, determine if it contains any dupli..

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

Given an array of length N containing integers between 1 and N, determine if it contains any dupli..

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

Post New Answer

More C Interview Questions

main() { printf("hello"); fork(); }

0 Answers   Wilco,


What is the difference between a free-standing and a hosted environment?

0 Answers   Aspire,


How reliable are floating-point comparisons?

0 Answers  


What are different storage class specifiers in c?

0 Answers  


What is malloc() function?

0 Answers  


which one is better structure or union?(other than the space occupied )

2 Answers  


hat is a pointer?

4 Answers   Assurgent,


Write a program to remove the C comments(/* */) and C++ comments(//) from a file. The file should be declared in command line.

4 Answers   Persistent, Subex,


Why & is used in scanf in c?

0 Answers  


can anyone suggest some site name..where i can get some good data structure puzzles???

0 Answers  


to get a line of text and count the number of vowels in it

2 Answers  


output for following code??? main() { int x=2,y,z; x*=3+2; printf("1.%d\n",x); x*=y=z=4; printf("2.%d %d %d\n",x,y,z); x=y==z; printf("3.%d\n",x); x==(y=z); printf("%d",x); }

2 Answers   Elysium,


Categories