Given an array of size N in which every number is between 1
and N, determine if there are any duplicates in it. You are
allowed to destroy the array if you like.
Answer Posted / ashish
just add as many n(length of array) to an index as much it
has duplicates i.e. if array has size 7 and no. 5 is written
3 times then add 7 three times.so that after first loop
completion, you can just take division (a[5-1]/7 in this
case.so u got 3.)
//array is a[]
//len=length of array
for(i=0;i<len;i++)
{
b=a[i]%len;
a[b-1]=a[b-1]+7;
}
//printing output
for(i=0;i<len;i++)
{
cout<<i+1<<" occurs: "<<(a[i]/7)<<endl;
}
Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Sir... please give some important coding questions asked by product companies..
how to programme using switch statements and fuctions, a programme that will output two even numbers, two odd numbers and two prime numbers of the users chioce.
how to test pierrot divisor
write a program for area of circumference of shapes
Write a routine to implement the polymarker function
What is the match merge ? compare data step match merge with proc sql merge - how many types are there ? data step vs proc sql
Cluster head selection in Wireless Sensor Network using C programming language.
What is data _null_? ,Explain with code when u need to use it in data step programming ?
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']
write a simple calculator c program to perform addition, subtraction, mul and div.
Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange
#include
How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.
Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?
write a c program to input initial & final time in the format hh:mm and find the time intervel between them? Ex inputs are initial 06:30 final 00:05 and 23:22 final 22.30