NVIDIA Interview Question for Software Engineer / Developers






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

@ YANG... assuming M is just a string ...meaning char *M = "100101110100101"

then pointer to string N say char *N = "10110"..

Now check for boundary condition.. ie
if(p>=0 && p<=strlen(M) && p<=q && q<=strlen(M) && q>=0)
if successful then check if(q-p == strlen(N)) if successful
increment M by (p-1) so as to make it point to pth bit in the string M.. i.e. M+=(p-1);
then in a loop
while(*M!= '\0' && *N!= '\0') // loop till end of string N and copy into string M
{
*M++ = *N++;
}

- CodeGeek January 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@ CodeGeek
Incrementing M+=(p-1); like this will take to NOT to the bit but to the byte (p-1) & that could be beyond your actual array.
I think the actual question is "We need to copy certain bits that could be at the locations like p = 15 & q = 21. so in this case we need to just copy 21-15=6 bits."

- increment by bit not by byte January 13, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am assuming M to be of 4 bytes & N to be of 1 byte (if that is not the case then we will have to look for iterative solution)

int M1 = 0;
take another array suppose M1. Initialize it with 0.

Then copy N left shifted by to M1 and then "&" it with M. This will make all bits in M that are 1 and those are NOT 1 in N as 0.
M1 = M & (N<< ( 1<<p));

After that copy N to M.
M = M | (N << (1 << p));

- Anonymous January 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Manipulate(M,N,p,q)
{
M=M&((N<<p+q)>>q);//if q>p
M=M|((N<<p+q)>>q);
}

- keshav January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. Mask bits between p & q(bitwise & operation).
2. then apply or (|) operation with N.

- Anonymous January 18, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1. bit makes between p & q and process the M
2. shit N ( N << p)
3. use "or " to get the final restuls
M | ( N << p)

- Anonymous January 07, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int a = ((N << (32-q+p))>>(32-q))
int b = (M>>q)<<q
int c = (M<<(32-p))>>(32-p)

M = a|b|c

- vikas B August 20, 2012 | 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