## InMobi Interview Question for Software Engineer / Developers

Team: InMobi
Country: India
Interview Type: In-Person

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

What is the first ugly num?

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

First ugly no is 1 when i=j=k=0; i,j,k belongs to Z+,i.e {0,1,2,3....}

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

First ugly no is 1 when i=j=k=0; i,j,k belongs to Z+,i.e {0,1,2,3....}

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

n-th ugly number is when i=j=k=n?
Is it?

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

a sequence of ugly numbers are :
<1,2,3,4,5,6,8,9,10,12,15,16,18,20........>

Note that all number are in the form of 2^i * 3^j * 5 ^k , i.e has only the factor : 2 or 3 or 5. For example 13 is not an Ugly number. 21 is also not an Ugly number as it can't be expressed as 2^i * 3^j * 5 ^k [ 7 is a factor ] . The ugly number are in increasing order, whre 1st elemnt is 1, second element is 2, 10-th element is 12. Find out n-th Ugly number ?

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

Use DP.

``````void foo(int n)
{
static int ind2,ind3,ind5;
static int arr[30],depth;
int num2,num3,num5,num,flag=0;
if(n<=0) return;
if(depth==0)
{
ind2=ind3=ind5=0;// i know this is redundant
arr[depth++]=1;
}
num2=arr[ind2]*2;
num3=arr[ind3]*3;
num5=arr[ind5]*5;

num=min(num2,min(num3,num5));

if(num==num2)
{
ind2++;
if(arr[depth-1]!=num2)
{
flag=1;
printf("%d\n",arr[depth-1]);
arr[depth++]=num2;
}
}
else if(num==num3)
{
ind3++;
if(arr[depth-1]!=num3)
{
flag=1;
printf("%d\n",arr[depth-1]);
arr[depth++]=num3;
}
}
else
{
ind5++;
if(arr[depth-1]!=num5)
{
flag=1;
printf("%d\n",arr[depth-1]);
arr[depth++]=num5;
}
}
if(flag)
foo(n-1);
else
foo(n);

}``````

Complete working code: ideone.com/qz4Py

It prints first n ugly numbers.

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

What is the first ugly num?

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

What is the first ugly num?

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

What is the first ugly num?

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

What is the first ugly num?

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

What is the first ugly num?

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

What is the first ugly num?

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

All even numbers are included in the list, only for odd numbers we can check whether it is divisible by 3 or 5 and included it. Is there any better approach?

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

Not all even numbers can be included,,,for example 14,,, 2^1 X 7^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.