Adobe Interview Question for Developer Program Engineers


Country: India
Interview Type: In-Person




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

here is a backtracking approach which prints the solution as well.

#include <stdio.h>
 
void coinDenomination(int *coin,int size,int *sol,int depth,int tofind,int start)
{
        int i;
        if(tofind<0)
                return ;
        if(tofind==0)
        {
                for(i=0;i<depth;i++)
                        printf("%d ",sol[i]);
                printf("\n");
        }
        else
        {
                for(i=start;i<size;i++)
                {
                        sol[depth]=coin[i];
                        coinDenomination(coin,size,sol,depth+1,tofind-coin[i],i);
                }
        }
}
 
int main()
{
        int coin[]={1,5,10,25},size,sol[50]={0},tofind;
 
        size=sizeof(coin)/sizeof(coin[0]);
 
        scanf("%d",&tofind);
 
        coinDenomination(coin,size,sol,0,tofind,0);
        
        return 0;
}

ideone.com/0ioYp

- Aashish July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 2 vote

DP solution

#include<stdio.h>

int getdenominations(int sum)
{
int arr[]={1,5,10,25};
int i,j;
int chan[sum+1];	//number of ways to make sum from given denominations
chan[0]=1;
chan[1]=0;

	for(i=1;i<=sum;i++)
		{
		chan[i]=0;		
		for(j=0;j<4;j++)
		   {
			if( (i-arr[j])<0 )
			continue;
			else
			chan[i]+=chan[i-arr[j] ];
		   }
		 }
return chan[sum];
}





int main()
{
int sum=5;
printf("%d ",getdenominations(sum) );

return 0;

}

- Luv July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Your program is giving wrong output for sum=11.
It is outputting 13: ideone.com/XFgdD
However the possible combinations are only 4:

1 1 1 1 1 1 1 1 1 1 1 
1 1 1 1 1 1 5 
1 5 5 
1 10

See here: ideone.com/fqmPE

- Aashish July 07, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Space - O(sum)
Time - O(sum)

- Luv July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static void MinimuumNoofCoins()
        {
            int[] denominations = new int[] {10,4,2,1};
            int sum = 14;
            int coincount = 0;
            int remainder = sum;
            int samecoincount = 0;
            bool flag = false;
            int count = 0;
            for(int i = 0; remainder != 0; )
            {
                if (sum % denominations[i] == 0)
                {
                    count = sum / denominations[i];
                    if (samecoincount != 0)
                    {
                        samecoincount = count < samecoincount ? count : samecoincount;
                    }
                    if (!flag)
                    { 
                        samecoincount = count;
                        flag = true;
                    }
                }

                if ((remainder % denominations[i]) == 0 )
                {
                    count = remainder / denominations[i];
                    remainder = remainder % denominations[i];
                    coincount += count;
                }
                
                if (remainder > denominations[i])
                {
                    count = remainder / denominations[i];
                    remainder = remainder % denominations[i];
                    coincount += count;
                    i++;
                }
                else i++;

                if (remainder == 0 && samecoincount!= 0) coincount = samecoincount < coincount ? samecoincount : coincount;
            }
            Console.WriteLine(coincount);

}

- Karthi July 04, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

@devsri: wat do u mean by working code? has adobe asked u to code actually?

- fire and ice August 02, 2012 | Flag Reply


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