Follow Our FB Page << CircleMedia.in >> for Daily Laughter. We Post Funny, Viral, Comedy Videos, Memes, Vines...


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

how does the C compiler interpret the following two statements p=p+x; q=q+y; a. p=p+x; q=q+y b. p=p+xq=q+y c. p=p+xq; q=q+y d. p=p+x/q=q+y

2 Answers   TCS, Tech Synergy,


Why do we use static in c?

0 Answers  


Finding first/last occurrence of a character in a string without using strchr( ) /strrchr( ) function.

2 Answers  


Magic square

0 Answers  


I use turbo C which allocates 2 bytes for integers and 4 bytes for long. I tried to declare array of size 500000 of long type using the following code... long *arr; arr=(long *)(malloc)(500000 * sizeof(long)); It gives a warning that "Conversion may lose significant digits in function main"... And the resulting array size was very less around 8400 as compared to 500000. Any suggestions will be welcomed....

2 Answers  






Can we change the value of static variable in c?

0 Answers  


Explain what is the difference between #include and #include 'file' ?

0 Answers  


Explain spaghetti programming?

0 Answers  


What is the difference between struct and typedef struct in c?

0 Answers  


. Consider the following program main() { int a[5]={1,3,6,7,0}; int *b; b=&a[2]; } The value of b[-1] is (A) 1 (B) 3 (C) -6 (D) none

9 Answers   Oracle,


what is the benefit of c30

2 Answers  


What is maximum size of array in c?

0 Answers  






Categories