## Google Interview Question for Software Engineer / Developers

• 0

Country: United States
Interview Type: Phone Interview

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

double Year(double x1,double x2,double R){
// If I need to check data
return log(x2/x1)/log(1+R);
}

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

If we know the formula of compound interest then this Question is Piece of Cake. Isn't?

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

``````int noYears(double x1, double x2, double R )
{
int n=0;

while ( x1 < x2 )
{
n++;
x1 = x1 + x1*R ;
}
if( x1 == x2)
return n;
else
return -1;
}``````

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

@siva.sai.2020, your solution works only if n is an integer.
It doesn't work if n needs to be 1.5 years e.g.

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

C++

int years (double &x1, double x2, double coef, int n) {

if ( x1 * coef > x2 ) {
return 0; }

int m = years(x1, x2, coef*coef, 2*n);

if ( x1 * coef < x2 ) {
x1 *= coef;
return m + n;
}
return m;
}

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

public static int getN(double r){
HashMap<Integer, Double> map=new HashMap();
int n=1, pn=0;
double v=(1+r), pv=1;
map.put(0, 1.0);
while(v<2){
map.put(n, v);
pn=n;
n*=2;
pv=v;
v=v*v;
}
if(v==2){
return n;
}
int c=pn;
double cv=pv;
while(n>=1){
n=pn;
pn/=2;
if(cv*map.get(pn)<2){
c+=pn;
cv*=map.get(pn);
}
else if(cv*map.get(pn)==2){
c+=pn;
return c;
}
}
return c+1;
}

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.