## NVIDIA Interview Question for Software Engineer / Developers

Country: United States
Interview Type: Phone Interview

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

2N

This is how i calculated
(2^N-1)(2^N-1) + 2^N-1 = (2^2N - 1) - (2^N-1)

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

which reduces to 2^2N - 2^N

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

It'd be
log(2){((2^N) - 1)((2^N) - 1) + ((2^N) - 1)}
= log(2) {2^2N - 2^N}
Leaving away -2^N, since we are looking for the highest number of bits,
we get
= log(2) {2^2N}
= 2N

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

another way of thinking:
for a * b, if b is a (N+1) bit unsigned integer, a * b means shift variable a N bits left, which results in a 2*N bit. And it's obvious that is reachable for a * b, since if a is the maximum digit for an N-bit integer, and b is 10...0(N zero following 1 one), then a * b is not the smallest 2*N-bit number

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

Why do we do a log operation in the calculation?

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

Why do we do a log operation in the calculation?

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

Another easy way to understand this is : consider N to be 8 bits or 1 byte... An unsigned int of 1 byte can have a max value of 255. Now applying the given equation with the maximum values possible:

a*b + c = 255*255 + 255 = 65280

we know unsigned 8 bit value max is 255 . Similarly unsigned 16 bit value is 65536 and 65280 is less than 65536. Hence we need 16bits for storing the result or 2N bits.

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

Don't forget to check your solutions with N = 1

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

also, what matters more is how you work throught the answer, not just come up with some fancy equation. Consider:
111*111 + 111 = 111 * (111 + 1)
The term in parentheses is at most N+1 bits and not greater than 2^(N+1) so it can shift by at most N bits. It turns into a simple shift by N bits, so the answer is 2N

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

2N +1

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

2N-1

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

say n is 3
then 111*111+111
=111*1000
=111000

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

= 2^(2N) - 2*2^N + 1 + 2^N - 1
should reduce to
2^2N - 2^N
and not
2^(2N) - 2^(N+ 1).
You might want to recheck your solution now.

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

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.

### 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.