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

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Which is better pointer or array?

587


What is break statement?

619


ATM machine and railway reservation class/object diagram

4792


What is a loop?

543


What is an lvalue in c?

684






What is mean by data types in c?

541


What are the benefits of c language?

637


Can we declare function inside main?

554


Describe explain how arrays can be passed to a user defined function

595


What is the difference between null pointer and wild pointer?

625


Explain what is dynamic data structure?

636


write a program to rearrange the array such way that all even elements should come first and next come odd

1749


Write a program to find the biggest number of three numbers in c?

580


Why isnt there a numbered, multi-level break statement to break out

577


Explain what is gets() function?

616