Microsoft Interview Question for SDE1s


Country: United States
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

Using ArrayBlockingQueue of size 32 bytes, will solve the problem.

- Lakshmanan July 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you explain with a code snippet if possible?

- FoogleDrive July 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Could you explain with a code snippet if possible?

- FoogleDrive July 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wouldn't this block the input device thread when the disk writer thread is accessing the queue's members? The input device cannot be blocked and needs to write data immediately .
Could you also provide a code snippet if possible?

- FoogleDrive July 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Let the input device write in to ArrayBlockingQueue<Byte>(8), synching between the input device and disk writer will be taken care by Blocking Queue.

- vsalaksh July 12, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Wouldn't this implementation block the input thread when disk writer thread is trying to access the queue members?
We cannot let the input device wait since it needs to immediately write available data to the buffer.

- FoogleDrive July 12, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Ok, in that case we need to have two queues of 16 bytes size, the input device first put the data in to the q1, once its full, it will move that in to disk writer and trigger disk writer (using countdown latch). And input device start putting the data in to q2. Once q2 become full(which will happen after 4 seconds), it will swap the queue to disk writer, then start writing in to the swapped queue

- vsalaksh July 13, 2015 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

maybe use a circle buffer list can solve it:

const int BUFSIZE = 1024;

class ListNode {
public: 
char *buffer;
ListNode() { buffer = new char[BUFSIZE]; } 
~ListNode() { delete[] buffer; }
};

ListNode *curr_read = new ListNode(), *curr_write = curr_read;
curr_read->next = curr_write;
int curr_read_ind = 0, curr_write_ind = 0;

void input(InputDevice in) {
    while (true) {
        if (curr_read_ind == BUFSIZE) { 
            curr_read_ind = 0; // reset read index
            if (curr_read->next == curr->write) { // create a new buffer node
                    ListNode *tmp = new ListNode();
                    tmp->next = curr->read->next;
                    curr->read->next = tmp;
            }
            curr_read = curr->read->next;
        }
        if (in.hasNext()) {
            curr_read->buffer[curr_read_ind] = in.read();
            curr_read_ind++;
        }
    }
}
void output(WriteDevice out) {
    while (true) {
        while (curr_write == curr_read) {} //wait for input device
        while (curr_write_ind != BUFSIZE) { out.write(curr_write->buffer[curr_write_ind]); curr_write_ind += 2; }
        curr_write_ind = 0;
        curr_write = curr_write->next;
    }
}

correct me if I'm wrong, thanks!

- Eidolon.C July 28, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Somewhat right, I guess the thing missing here is output writer can only access the buffer only when size of buffer is greater than say, 16 bytes, while input device can keep writing to the front of the queue.
I wonder if this would cause any issues related to thread safety though!

- foogle August 02, 2015 | Flag


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More