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

How can I do serial ("comm") port I/O?

1184


What is #define size in c?

1203


What is hashing in c language?

1324


Is c procedural or object oriented?

1032


Why are all header files not declared in every c program?

1112


State the difference between realloc and free.

1101


#include { printf("Hello"); } how compile time affects when we add additional header file .

1907


Explain the use of #pragma exit?

1183


What are the valid places to have keyword “break”?

1093


Explain the properties of union.

1091


In a byte, what is the maximum decimal number that you can accommodate?

1147


Can you tell me how to check whether a linked list is circular?

1434


What is the difference between break and continue?

1549


How do you view the path?

1138


why wipro wase

2321