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
Write a program to show the change in position of a cursor using c
Why enum is used in c?
Explain what happens if you free a pointer twice?
What is bss in c?
What is the purpose of & in scanf?
Can we use visual studio for c?
What is a volatile keyword in c?
When should a type cast not be used?
What is the equivalent code of the following statement in WHILE LOOP format?
Explain union. What are its advantages?
What is nested structure?
write a c programming using command line argument,demonstrate set operation(eg;union,intersection,difference) example output is c:>setop 12 34 45 1 union 34 42 66 c:>setop 12 34 1 42 66 c:>setop 12 34 diff 12 56 67 78 setop 12 34
What is the use of typedef in c?
Explain what is the general form of a c program?
Explain c preprocessor?