## Adobe Interview Question for Developer Program Engineers

• 0

Country: India
Interview Type: In-Person

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

Optimized version. It's producing 1001 combinations.

``````for(int c = 25; c >= 0; c--)
{
for(int b = 50; b >= 0; b--)
{
if(100-c-b <= 75)
{
std::cout<<"A = "<<100-c-b<<", B = "<<b<<", C = "<<c<<std::endl;
}
}
}``````

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

Start from an initial configuration like:

``C=25, B=0, A=75``

Keeping C fixed at 25, the configuration can be changed to the below in 51 steps

``C=25, B=50, A=25``

A change from configuration C=24, B=1, A=75 to C=24, B=50, A=26 is obtained in 50 steps. Continuing this way, a change from configuration C=0, B=25, A=75 to C=0, B=50, A=50 requires 26 steps.

Therefore the total number of configurations = 26 + 27 + ... + 51 = 1001.

``````public class CoinDistribution {

public static void main (String[] args) {
distribute();
}

public static void distribute() {
int c = 25, b = 0, a = 75, counter = 1, k = 0;

while(k <= 25) {
for (int j  =  k, d = 0; j <= 50; j++, d++) {
System.out.println(counter++ + ". C=" + (c-k) + ", B=" + j + ", A=" + (75-d));
}
k++;
}
}
}``````

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

Dumbo change your name.. u r not one :P . Till now it looks good but not very much sure :)

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

@CodeCracker

Thanks for the suggestion :). I will try to change it.

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

Quote: In how many ways you can distribute these 100 coins to all the 3 beggars.
Notice the "to all the 3 beggars" might mean we never give 0 coins to a beggar.

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

``````Logic:
2 for is enough for this problem:

# include <stdio.h>

int a,b,c;

int main ()
{
for(c=25;c>=0;c--)
{
for(b=50;b>=0;b--)
{
if(b+c>=25)
{
a=(100-b-c);
cout<<"Data: A="<<a<<"    B="<<b<<"    C="<<c<<"   Total="<<a+b+c<<"\n";
}
}
}

return 0;
}``````

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

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

@Dumbo @Nascent : I think it can further be optimized. Let me know your comments on the code below.

``````int a=b=c=count=0;
for (a = 25; a<=75 ;a++)
{ for (b=0; b<= min(50,100-a); b++)
{ for (c=0; c<= min(25,100-a-b); c++)
if((a+b+c)==100)
count++;
}
}``````

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

``````for(c=C ; c>=0 ; c--)
{
for(b=(C-c), a=A; b<=B ; b++,a--)
{
printf("%d %d %d \n",c,b,a);
}``````

}

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

the minimum number of comparisons is going to be 50 * 25 = 1250 ..

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

It will be the coefficient of x^100 in (1+x+x^2+.........x^75)*(1+x+x^2+.........x^50)*(1+x+x^2+.........x^25)

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

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

Constraints wont be maintained. With this you also will get output as 75 + 50 + 25 and so on and so forth

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

for (i=1;i<=75;i++)
{
for (j=1;j<=50;j++)
{
for (k=1;k<=25;k++)
{
if((i+j+k)==100) // ADD this condition
{
System.out.println("A=" +i);
System.out.println("B=" +j);
System.out.println("C=" +k);
}

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

@Nascent

Good one, though, code needs some more fixes:

``````for (i=25;i<=75;i++) // A can be started from 25, because B+C can together hold a maximum of 75

for (j=0;j<=50;j++) // j should start from 0, because B can be 0

for (k=0;k<=25;k++) // k should start from 0, because C can be 0.``````

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

``````int DistributeCoin(int total, int A, int B, int C)
{
int count(0);

for(int i = 25; i <= A; ++i){
for(int j = 0; j <= B && (i + j) <= 100; ++j){
if(100 - i - j <= C){
count ++;
}
}
}

return count;
}``````

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.