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
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 |
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 |
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 |
How can I find leaf node with smallest level in a binary tree?
Explain data types & how many data types supported by c?
What is the difference between fread and fwrite function?
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.
What is const volatile variable in c?
Why c is called procedure oriented language?
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?
Tell us something about keyword 'auto'.
How do you sort filenames in a directory?
What should malloc() do? Return a null pointer or a pointer to 0 bytes?
12345 1234 123 12 1
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