NVIDIA Interview Question for Software Engineer / Developers


Country: United States




Comment hidden because of low score. Click to expand.
7
of 9 vote

float SquareRoot(float num)
{
if(num >= 0)
{
float x = num;
int i;
for(i = 0; i < 20; i ++)
{
x = (((x * x) + num) / (2 * x));
}
return x;
}
}

- Anonymous May 15, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nice sln

- Daru July 21, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Can someone please explain the logic?

- Anonymous March 09, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is exactly Newton's iterative method mentioned below.

- micropie May 12, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

There is a possibility of overflow.

Better make it :

(x + num/x)/2

- PJ August 17, 2014 | Flag
Comment hidden because of low score. Click to expand.
3
of 3 vote

You can use Newton's iterative method
Ai+1 = 0.5 * (Ai + X/Ai); where i - number of iteration

- V.Krestyannikov May 06, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

#include<stdio.h>
#include<math.h>

void main()
{
float a,b,c;
printf("\n enther the number square root who wanna found\n");
scanf("%f",&a);
int i,j;
b=a;
for(i=1;i<10;i++)
{
b=0.5*(b+a/b);
}
printf("\nsqrt of %f is %f\n\n",i,a,b);
}

- Kunal Bansal July 30, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This fails for a large number like 1,000,000.

- Anonymous March 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

I am not sure how it fails for large numbers. The number you used is not particularly larger considering we are using floats here, right? There will be precision loss because of using floats but it shouldn't be too bad, imho.

- manish.baj March 25, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Float sqrt(float num)
{
Float x;
If(num >0)
{
for(i=0;I<20;i++)
{
x=(x*x+num)/(2*x);
}
Return x;
}
}

- fargusan May 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you explain what is it doing??

- bjain May 15, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

can u please explain wat is happening here.....

- Anonymous December 02, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

class Solution {

public int mySqrt(int target) {
long start=1;
long ans=0;
long end=target;
if(target==0)
return target;
while(start<=end)
{
long mid=start+(end-start)/2;
if(mid*mid==target)
{
return (int)mid;
}
else if(mid*mid<target)
{
ans=mid;
start=mid+1;
}
else
{
end=mid-1;

}
}
return (int)ans;

}

}

}

- varshil August 19, 2021 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

float thresh = 0.0000001

float binarysearch(float x, float y, float z)
{
if (x*x < z-thresh && y*y > z+thresh)
{
x = binarysearch((x+y)/2,y,z);
}
else if (x*x > (z+ thresh))
{
x = binarysearch(x/2,x,z);
}
return x;

}


float sqrt(float x)
{
return binarysearch(0,x+1,x);
}

- Anonymous June 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

milo please dont type rubbish

- sandeep May 08, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
1
of 1 vote

I don't know what he means by linear search, but binary search is definitely not rubbish.

- eugene.yarovoi May 08, 2012 | Flag
Comment hidden because of low score. Click to expand.


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