Microsoft Interview Question
InternsCountry: United States
Interview Type: In-Person
basically, it's just
print(int x)
{
int i, j;
stack<int> s;
for(; i != 0; )
{
r = x/10
i = i mod 10;
s.push(r);
}
for(char c = ' '; !s.isEmpty(); ){
c = integer to character(s.pop());
print(c);
}
}
This was the direction that he directed me.
At first, I was thinking of bits because I was quite taken aback of the question since it was like asking, write a text editor without using a text editor you know. It was the first interview!!!! Anyways, I didn't ask about system calls and such because he mentioned during the interview writing it in python because he wanted to introduce his programming language lisp to me. Just a word of advice, don't expect that you'll know the topic. If you are interested in compilers, just make sure to be clear that you are interested in it, not actually started implementing it in your room or something!
Thanks for answering guys. I seriously didn't know how to approach the problem cause it wasn't the classical interview question I was used to, aka - data structures, sorting, complexity, etc... I didn't think that if I were to talk a little bit about my side research on compilers and program analysis that I'm just beginning, he would then throw me a compilers question <WTF>. Be clear about your strengths and what you've actually done so that they expect to give you a question that will show your full capabilities.
But at least I got to talk to my interviewee about compilers and reminisce about his college life even though, I couldn't understand what he was asking me.
lets say. our print method takes a byte and uses character map to print character corresponding to given byte. Now, we can represent 0-9 digit easily in byte an their corresponding character will be '0','1'...'9'.
So. if can covert given integer to array of digit and send each digit to print method. we can print that digit
without using inbuilt print method.
Something like this?
- Here we go Mario March 01, 2013#include <unistd.h>
int main(void)
{
const char hello[] = "Hello World!\n";
const size_t hello_size = sizeof(hello);
ssize_t ret;
asm volatile
(
"movl $1, %%eax\n\t"
"movl $1, %%edi\n\t"
"movq %1, %%rsi\n\t"
"movl %2, %%edx\n\t"
"syscall"
: "=a"(ret)
: "g"(hello), "g"(hello_size)
: "%rdi", "%rsi", "%rdx", "%rcx", "%r11"
);
return 0;
}