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

What is wrong with this code?

0 Answers  


Write a code to determine the total number of stops an elevator would take to serve N number of people.

0 Answers   Expedia,


How can you access memory located at a certain address?

0 Answers  


Which is better malloc or calloc?

0 Answers  


i=10,j=20 j=i,j?(i,j)?i:j:j print i,j

1 Answers   CSC,






What does c mean in basketball?

0 Answers  


What is the use of getchar() function?

0 Answers  


Why is c so powerful?

0 Answers  


dibakar & vekatesh..uttejana here..abt ur reply for in place reversal of linked list..wats p stands for there?

1 Answers  


writw a program to insert an element in the begning of a doubly linked list

1 Answers  


how to write hello word without using semicolon at the end?

6 Answers   Accenture,


write a program to display the array elements in reverse order in c language

16 Answers  


Categories