Adobe Interview Question for Developer Program Engineers


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;
			}
		}
	}

- techie guy July 10, 2013 | Flag Reply
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++;
		}
	}
}

- Murali Mohan July 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Stupid Developer July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

@CodeCracker

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

- Murali Mohan July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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.

- Michael July 08, 2013 | Flag
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;
}

- PKT July 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Code Please ??

- Stupid Developer July 08, 2013 | Flag Reply
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++;
               }
         }

- Learner July 08, 2013 | Flag Reply
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);
        }

}

- gaurav414u July 11, 2013 | Flag Reply
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 ..

- kaush July 23, 2013 | Flag Reply
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)

- ravi pradeep July 08, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Code Please ???

- Stupid Developer July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 votes

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

- Stupid Developer July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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);
}

- Nascent July 08, 2013 | Flag
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.

- Murali Mohan July 08, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

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;
}

- Anonymous July 09, 2013 | Flag


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