Yahoo sample interview questions and answers

Yahoo interview questions
1). What is the output?
main()
{
char hi[2]="HI";
cout<<<<'> hi<<' '<<"Hello"; } Ans: It will give error. 'HI' : array bounds overflow (Because string contains '\0' implicitly. "Hi" is of length 3.

2). Write a STRING class. Implement
- default constructor,
- Copy Constructor,
- Assignment Operator,
- String length function
- String Copy function
- String concatenation,
- Destructor

3). How to find the only unique number from a list of N integers where all are duplicates except one. Find the unique number in O(n) time.


Ans: start from the first element of the array and keep XORing it with the rest of the elements saving the result.
{
j=a[0];
for(i=1;i<>
{
j=j^a[i];
}
printf("\n\nThe Unique is %d\n\n",j);
}

4). Design patterns in c++

No comments:

 
Top Blogs