## Microsoft Interview Question

Software Engineers**Country:**United States

```
unction smallest_factors(n) {
let result = `no result found for ${n}`,
product;
if( n < 10 ) return n;
for(let i=+n+1; i<Number.MAX_SAFE_INTEGER; i++) {
const sa = (''+i).split('');
//console.log(sa);
product = sa.reduce((acc,cur) => {
//console.log(`entered reduce: acc=${acc}, cur=${cur}`);
acc *= +cur;
//console.log(`leaving reduce: acc=${acc}, cur=${cur}`);
return acc;
}, 1);
//console.log(`product=${product}`);
if( n == product ) {
result = i;
break;
}
}
return result;
}
```

```
unction smallest_factors(n) {
let result = `no result found for ${n}`,
product;
if( n < 10 ) return n;
for(let i=+n+1; i<Number.MAX_SAFE_INTEGER; i++) {
const sa = (''+i).split('');
product = sa.reduce((acc,cur) => {
acc *= +cur;
return acc;
}, 1);
if( n == product ) {
result = i;
break;
}
}
return result;
}
```

```
import java.util.*;
import java.lang.*;
import java.io.*;
class test
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner s=new Scanner(System.in);
int n=s.nextInt();
for(int i=n+1;i<2*n;i++){
int result=1;
int t=i;
while(t>0){
result=result*(t%10);
t=t/10;
}
if(result==n){
System.out.println(i);
break;}
}
}
}
```

if numbers are prime it will not print any thing.

Looking for interview experience sharing and coaching?

Visit AONECODE.COM for ONE-ON-ONE private lessons by FB, Google and Uber engineers!

SYSTEM DESIGN

ALGORITHMS (conquer DP, Greedy, Graph, Advanced Algorithms, Clean Coding),

latest interview questions sorted by companies,

mock interviews.

Get hired from G, U, FB, Amazon, LinkedIn, Yahoo and other top-tier companies after weeks of training.

Email us aonecoding@gmail.com with any questions. Thanks!

SOLUTION:

followup: what if we need to worry about the integer overflow?

- aonecoding June 06, 2018