Microsoft Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

Iterate over the array elements, and decode the type of the current element:
- if in the range of [0,127] then it's the first byte of a one byte character
- if in the range of [128,255] then it's the first byte of a two byte character. Move to the next array element, and mark it as the second byte of a two byte character.
Stop when the current pointer equals the pointer that we search for and report the type found.

- ranan.fraer May 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Can you explain a bit, did not understand what you meant by- "two pointers are given, one points to the start of the and another points to somewhere else. "

- HardCode May 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This question is quite vague and I'm not sure if I got it right.
You have two pointers which point to some locations in the array.
Iterate over the array and find that locations.
Now you have four possibilities:

if ((p1 && p2) < 128) - there are two 'one byte' numbers 
if ((p1 && p2) >= 128) - there are two '2 byte' numbers - both pointers can point to first digit
if ((p1 >= 128 &&  p2 < 127) - there is one '2 byte' number - p1 is first digit
if ((p2 >= 128 &&  p1 < 127) - there is one '2 byte' number - p2 is first digit

- Anonymous May 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

>> one points to the start of the and...
I guess this should be "to the start of the array"

while (p1 < p2)
{
    if ((arr[p1] & 0x80) == 0)
    {
        p1 += 1;
    }
    else
    {
        p1 += 2;
    }
}

if (p1 == p2)
{
    if ((arr[p2] & 0x80) == 0)
    {
        // p2 points to a single-byte char: arr[p2]
    }
    else
    {
        // p2 points to a double-byte char: arr[p2], arr[p2+1]
    }
}
else
{
    // p2 points in the middle of a double-byte char.
}

- v.shashenko May 17, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Move the first pointer to just the byte before the second pointer.
Now check the value. If it's between 0 to 127 then either way it is the last byte. Hence if the second pointer is > 128 then it is the first byte of the two byte word else is the one byte word.
if the value of first pointer is >128 then the second pointer is definitely the second byte of the two byte word.

- Learn July 15, 2014 | Flag Reply


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