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 can I find leaf node with smallest level in a binary tree?

1 Answers  


Explain data types & how many data types supported by c?

0 Answers  


What is the difference between fread and fwrite function?

0 Answers  


Write a program in C for showing working of different logical operator in C. Your program should guide users with proper message/menu on the console.

3 Answers   HCL,


What is const volatile variable in c?

0 Answers  






Why c is called procedure oriented language?

0 Answers  


Write a main() program that calls this function at least 10 times. Try implementing this function in two different ways. First, use an external variable to store the count. Second, use a local variable. Which is more appropriate?

2 Answers  


Tell us something about keyword 'auto'.

0 Answers  


How do you sort filenames in a directory?

0 Answers  


What should malloc() do? Return a null pointer or a pointer to 0 bytes?

0 Answers  


12345 1234 123 12 1

2 Answers  


An interactive c program to read basic salary of 15 persons. each person gets 25% of basic as HRA, 15%of basic as conveyance allowances, 10%of basic as entertainment allowances.The total salary is calculated by adding basic+HRA+CA+EA.Calculate how many out of 15 get salary above 10,000.Rs also print the salary of each employee

2 Answers  


Categories