LET'S TALK TECHNICAL

This blog is intended to help people prepare for the job interviews and improve their analytical skills. We have posted difficult datastructures and algorithm questions and puzzles. Interview experiences section is for the people to post their interview experiences.Views expressed here are of their personal and the blog author doesn't take any responsibility for the same.

-

Followers

Jobs

Saturday, November 10, 2007

How to check if the stack grows up or down?

Instantiate a local variable in main function(caller) and instantiate another local variable in callee function. Compare both the addresses. If address of local variable declared in main in less than the address of local variable in function(callee) then the stack is growing towards higher address.
Here is the Program which does this:
int main()
{
int localinmain;
CheckStackGrowth(&localinmain);

}

void CheckStackGrowth(int *localinmain)
{
int localinfunction;
if(localinmain < &localinfunction)
printf("Stack is growing downwards.\n");
else
printf("Stack is growing upwards.\n");


}

Friday, November 9, 2007

Interview With Google.

Recently I have attended telephonic Interview with Google for the post of Sr. S/W Engineer in their internal application team. Someone named XYZ called me from their Mountainview office. It was around 10:30 PM (was already feeling sleepy). He started with asking me something about my previous projects and asked most challenging work i have done so far. Then he asked me about the languages i am comfortable with.
Then he asked whether i have used Microsoft Excel. Then he asked me the logic to convert column headers in excel sheet to numbers. Something like (A->1, B->2.......Z->26, AA->27 ....). Given the column header it should return the number mapping to it.
My answer was to use the number system with base 26. Store the column header in a string and extract each character and do ch-'A'+1(ascii diff) to get the index value corresponding to the number and multiply it with 26 ^(character positon -1) and add it to the result.

He accepted the answer and asked me to write the code for the same. I have written it in C and dictated it to him on phone. He then asked me to calculate the complexity of the same. I gave both the space and time complexity of my algorithm.

Next he asked me the logic to find the Square root of the number without using Square root function.

I gave him the numerical method answer... (Thank god i still remember some of my numerical method classes which i attended 8 years back). My answer was something like below.

double guess = num/2, oldguess = 0;
while(guess != oldguess) {
oldguess = guess;
guess = (num/guess + guess)/2;
}
return guess;

He was happy with my answer and asked me about the possible test cases i will have for it.
I gave him 0,1, negative numbers and numbers out of double range.. etc..............
He said excellent.
During the course of interview he was saying only few words like sounds good, make sense, excellent etc..

He then said he is done from his side and enquired whether i have any questions for him.
After one hour i got a chance to make him talk.... so i don't want to miss this opportunity and asked him about the kind of work they do ? Their work culture? etc... (even though i know answers from them.. :-))

He replied back saying G is a great company and talked about 20% time which we can use for personal projects... blah..blah .. blah...

Next day i got a call from their HR asking for my time for the onsite inerviews.....

Will keep posting my further rounds here.. .. do let me know the feedback..

incrementing void pointer?

Will the following program execute?void main()
{
void *vptr = (void *) malloc(sizeof(void));
vptr++;
}


Output of this program depends on the compiler।
1) If you are using a ANSI C or C++ compiler then you cannot take the sizeof(void) and you cannot increment a void* pointer. So, you will get the follwoing errors.

ANSI C++ forbids taking the sizeof a void type.
ANSI C++ forbids incrementing a pointer of type `void *'

NOTE: Try this with CC compiler under unix

2)If you are using gcc compiler then sizeof(void) will return 1.
so one byte will be allocated and when u try to increment the void* pointer it will be incremented by one byte.

NOTE: output as seen in gdb;
(gdb) p sizeof(void)
$1 = 1
(gdb) p vptr
$5 = (void *) 0x13030
(gdb) n
4 vptr++;
(gdb) p vptr
$6 = (void *) 0x13031

Is the size of an Integer Platform Dependent or Architecture Dependent?

platform dependent means based on operating system architecture.
ie in some of 32 bit OS, the size of int is 2byte and in some of 64 bit OS, the size of int is 4 byte. It also varies based on the compiler used.
Example: in VC++ it is 4byte and in TC++ it is 2 byte

How can I test whether my system’s byte order is big endian or little endian.?

Little endian and Big Endian refer to the layout of byte in which the data is stored.

Big endian : Stores most significant data of information from the base address.
Little Endian : Stores from least significant data from the base address.

let us take an example :

I want to store 14 in an integer on a 32bit machine.

in the binary pattern the number is represented as 1110.
If the same is to be stored in a 32bit alignment.

Big Endian stored it like :

0000-0000 0000-0000 0000-0000 0000-1110

Little Endian stores it like :
0000-1110 0000-0000 0000-0000 0000-0000

So the following program might help you in knowing whether your machine is of Little-Endian or Big Endian Architecture.

void main()
{
int i = 1;
char *c = (char *)&i;

if ( *c == 1 )
{
cout<<" LITTLE ENDIAN";
}
else
{
cout<<" BIG ENDIAN";
}
}

When the processor wakes up after power on, it goes to a particular memory location. What is that memory location called?

When power is switched on , the CPU wakes up and makes chipset(mostly intel bases ones) to look for top 16 bytes of the first MB of the MEMORY where BIOS code is placed in compressed format.

NOTE: Additional info about booting process.

Then CPU decompress the BIOS code and BIOS code will get system settings (remember the BIOS settings we set at boot time in ROM BIOS) from chipset registers.Then BIOS configures the memory and copies BIOS code to RAM (shadowing). Then all the controller(SCSI,N/w cards,video card) BIOSes are shadowed. After this PCI bus gets initialized and basic devices required for computer to boot are given Interrupts and DMA channels.
After this we will see that memory counting screen which we get after starting our system.

Then BIOS executes the bootloader to load MBR(Master Boot record). Then Interrupt vector is created and OS is loaded.BIOS will be deactivated once OS gets loaded.

Popular Posts