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..

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..

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..

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

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

Why do we use static in c?

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

Magic square

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....

Can we change the value of static variable in c?

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

Explain spaghetti programming?

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

. 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

what is the benefit of c30

What is maximum size of array in c?

Categories