Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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. [ I ended up giving about 4 or
5 different solutions for this, each supposedly better than the
others ].



Given an array of size N in which every number is between 1 and N, determine if there are any dupli..

Answer / sujan_faith

<!--i have just replaced the same array element with
the value zero but alse we can destroy that element-->>


#include<iostream>
#define size 10
using namespace std;

int main()
{
int a[10]={10,10,10,2,1,1,1,1,1,2};
int j=1;
for(int i=0;i<size;i++)
{
for(int k=i+1;k<size;k++)
{
if(a[i]==a[k]&&a[i]!=0)
{
a[k]=0;
j++;

}
if(k==(size-1)&& a[i]!=0)
cout<<"Value is: "<<a[i]<<" which is repeated "<<j<<" times"<<endl;
}
j=1;
}
system("pause");
}

Is This Answer Correct ?    8 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is token c++?

0 Answers  


What is a static member?

0 Answers  


Explain binary search.

0 Answers  


Name the operators that cannot be overloaded in C++?

0 Answers   Fidelity,


write a program to insert an element into an array

26 Answers   TCS,


What is the difference between *p++ and (*p)++ ?

0 Answers  


Differentiate between late binding and early binding.

0 Answers  


You have to take 2 arrays of length 10. Input the values of array 1 from the user. Then copy the values of array 1 to array 2 in ascending order For example if user enters 9, 5, 6, 8, 1, 0, 2, 7, 4, 3 then copy the smallest element i.e. 0 first followed by 1, 2 and so

1 Answers  


int age=35; if(age>80) {Console.WriteLine("Boy you are old");} else {Console.WrieLine("That is a good age");}

0 Answers  


What are the different operators in C++?

3 Answers   HP,


What are the benefits of operator overloading?

0 Answers  


Write a short code using c++ to print out all odd number from 1 to 100 using a for loop

0 Answers  


Categories