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 numbers, except for one number all the
others occur twice. Give an algorithm to find that number
which occurs only once in the array.

Answer Posted / deepak

/*
you can also do some pre tests like array length should be odd.

just take an XOR of all the numbers it will give u the
number that occured single time.

it assumes that data is in correct form i.e. there is one
and only one number that occurs once.
*/
public static int whoOccursSingleTime(int a[]){
int s=0;
for(int i=0;i<a.length;i++){
s=s^a[i];
}
return s;
}

Is This Answer Correct ?    19 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is clrscr in c?

1091


What is the difference between a function and a method in c?

1047


How is pointer initialized in c?

992


What is mean by Data Driven framework in QTP? Can any one answer me in details on this regard.

2217


What do header files do?

1037


What is difference between far and near pointers?

1001


Describe the modifier in c?

1067


What is the explanation for the dangling pointer in c?

1077


How does free() know explain how much memory to release?

1024


What is the 'named constructor idiom'?

1046


What is a null pointer in c?

1152


What are the types of pointers in c?

987


What is main return c?

945


Explain continue keyword in c

978


Are the variables argc and argv are always local to main?

986