Sunday, February 21, 2010

Adobe Interview Round1

1) Basic C++ question .A class definition was given and then objects of that class were created in main function.
like
class string
{
int a;
int b;
int c;
void print()
{
printf("%d%d%d",&a,&b,&c);
}

};

main()
{
string s1,s2;
s1.a=s1.b=s1.c=10;

s1 =s2;
s1.print();
string s3=s2;
s3.print();
s2.print();
}

basically he was trying to get whether i understood what happens when s1=s2 and at string s3=s2;

2) What is the difference between a big endian and little endian machine?
Can you write a code to identify them.

sol int x=1;

if(x<<1)
printf("big endian");
else "little endian";


3)Do you know what is inorder traversal and BFS.
given a sample tree do that.
write code for inorder.
I wrote recursive then he asked me for iterative.

4)An array of numbers is given which are sorted you are also given a number 'X'.
you need to print to 2 elements of array such that there sum is X.


since the elements are sorted , to search for any element we can for binary search. now subtract x from a[0] and search for the result in array.
this wud cost me o(nlogn)


5) Given i/p "My name is khan" o/p shud be "khan is my name"

one approach wud be to use linked list , wherein we use each node to store a word.

my->name->is->khan.

Now do linked list reverse operation.

by using this even multiple space between words can be taken care of.
my->space,space->name->...
i.e in the node which stores space i will store that many space characters which are present.

Interviewer asked me to get a solution without extra memory usage.
DO string reversal nahk si eman ym
now do word by word reverse khan is name my

6)char a[]="string"; char *p="string";
there are several difference b/w a and p
most imp one is that u can do free(p) but not free(a);

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.