Adobe Interview Question for Software Engineer / Developers






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

change(n)= 1+ min({change(n-1),change(n-2),change(n-5)})
where 1,2,5 are sample denominations..

- MVP January 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I don't understand why DP is needed with O(n) complexity.

What's the issue with being greedy and always use the highest value coins whenever possible and use the next highest value ones and so on. This is O(1). Would someone please point out if there is a fault to this logic?

- ep August 05, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

Greedy approach won't work. I was asked the same question by Amazon and I gave him a greedy approach and the interviewer proved me wrong with a simple example.

Say,
coins = { 1, 10, 25 }
amount = 30

Greedy approach will choose 25 first and then five coins of value 1.

Dynamic will choose 3 10's.

- LAP December 06, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

Standard DP solution for this problem...

int sum  = 11; // the change sum you want
    vector<int> value;
    value.push_back(1),value.push_back(3),value.push_back(5); // for testing purpose vector of denominators
    vector<int> minCoinsForSum(sum+1,INT_MAX); //state Array for DP
    minCoinsForSum[0] = 0;
    for(int i = 1;i<=sum; ++i)
        for(int j = 0;j<(int)value.size() ;++j)
            if(value[j]<=i && (minCoinsForSum[i-value[j]]+1) < minCoinsForSum[i])
                minCoinsForSum[i] = minCoinsForSum[i - value[j]] + 1;

    for(int i=0; i <(int)minCoinsForSum.size(); i++)
        cout<<minCoinsForSum[i]<<endl;

    return 0;

- Bazinga November 16, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public string ReturnMinChange(int cents)
{
// Let's say I have 25, 10, 5, and 1 cetns to give
string giveReturn = string.Empty;
int[] centsArr = new int[] { 25, 10, 5, 1};
foreach (int i in centsArr)
{
if (cents >= i)
{
giveReturn += (cents / i) + " " + i + " cents, ";
cents = cents % i;
if (cents == 0) break;
}
}
return giveReturn;
}

- Raj January 16, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is not correct.
For example if you have coins of 20, 15 and 1 and you have to totalamount = 31

- spiderman January 17, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

The question is not clear to me :(

- Princy January 18, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

This shud work..................
{
void main()
{
cout<<"Hello World!"<<endl;
int coins[3] = {20, 15, 1};
int val = 31;
int rem = 0;
int i = 0;
int num = 0;
while ( 1 )
{
num = val / coins[i];
rem = val % coins[i];
if(!rem)
break;

cout << num << " coins required of denomination " << coins[i] << endl;
i++;
val = rem;
}
cout << num << " coins required of denomination " << coins[i] << endl;
}
}

- AA January 19, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

nope u r wrong.. this is a classic DP algo of complexity ND where N=value D=no.of Denominations...check out the 1st soln posted its perfect..

- Anonymous January 19, 2009 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Agreed .. but if u look closely, both r the same... only variables names are different

- AA January 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess the first solution doesn't have variables. It just gives the correct recurrent function :-)

- Evgeny January 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

AA is totally wrong, he obviously didn't even run his code.

linear programing solves this easily, but I will think about it for a second.

- Anonymous January 21, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

is the question:
if i have multiple 25, 10, 5, and 1 cents.
and lets say i want to give some number of change to someone.
find the algo to provide the change with minimum coins.

that means, if change number is 55, i should give (2)25 cents, and (1)5 cents. Instead of (11)5 cents or (55)1 cents.

Spiderman, please clarify this

- bb January 22, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

try running the code , then comment

- AA January 28, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int main()
{
int coins[4] = { 25,10,5,1};
int amount;
int i;
int numCoins;

cout<<"\n Enter the amount";
cin>>amount;
for(i=0;i<4;i++)
{
numCoins = amount/coins[i];
amount = amount - numCoins*coins[i];
cout<<"\n required "<<numCoins<<" of denominaion "<<coins[i];

if(amount == 0)
break;
}
return 0;
}
hope this should help.

- arunkumar.viswanath May 30, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

This is not correct.
For example if you have coins of 20, 15 and 1 and you have to totalamount = 31

- Psycho October 09, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

this can be solved using dp..
let C[p] represent the min no of coins needed for getting amount p
let d is the array of denominators(size k)
then we can write the recurrence as follows:

C[p]=0 if p=0
= min(1 + C[p-d[i]]) here d[i]<=p and 1<=i<=k

then just calculate the array C[] in bottom up fashion
time complexity: O(nk)

- idea July 20, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

almost missed that.

- thanks July 13, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class MinimumChange {
public static HashMap<Integer,Integer> minimumChange(int [] a ,int k,int amount){
if(k > 0){
int temp=amount;
int remainingAmount=1000;
int denominationCount;
HashMap<Integer, Integer> map=new HashMap<Integer, Integer>();
for(int i=k;i>=0;i--){
if(remainingAmount <= 0){
break;
}
denominationCount=temp/a[i];
temp=temp%a[i];
remainingAmount=temp;
map.put(a[i], denominationCount);
}
if(remainingAmount==0){
return map;
}
else{
return minimumChange(a,k-1,amount);
}
}
return null;
}
public static void main(String[] args) {
int [] a ={3,4,5};
int len=a.length;
HashMap<Integer, Integer> map=minimumChange(a,len-1,12);
System.out.println(map);
}

}

- chandy June 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Is this algorithm correct?

- Anonymous June 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

{
// CoinDenomination.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<Windows.h>
#include<atlstr.h>
typedef struct _deno
{
	CString individualDeno;
	CString denominations;
	int cnt;
	_deno()
	{
		individualDeno = _T("");
		denominations = _T("");
		cnt = -1;
	}
}Deno;
int getMin(int n,int *denom,int denomcnt,int currentNum,Deno *denomidations)
{
	
	int min = n + 1;
	int cnt = -1;
	for(int i=0;i<denomcnt;i++)
	{
		if(denom[i] <= currentNum)
		{
			int x = currentNum % denom[i];
			int y = currentNum/denom[i];
			if(!x)
			{
				cnt = denomidations[denom[i]].cnt * y;
				if(cnt < min)
				{
					min = cnt;
				}
			}
			else
			{
				if((denomidations[x].cnt != -1) || (denomidations[x].cnt != -2))
				{
					cnt = denomidations[denom[i]].cnt * y + denomidations[x].cnt;
					if(cnt < min)
					{
						min = cnt;
					}
				}
			}
		}
	}
	denomidations[currentNum].cnt = min;

	return min;

}
int FunmindenomCnt(int n,int *denom,int denomcnt)
{
	Deno *denominations = new Deno[n];
	int minDenom;
	for(int i=0;i<denomcnt;i++)
	{
		denominations[denom[i]].cnt = 1;
	}
	for(int i=0;i<=n;i++)
	{
		if(i >= denom[0])
		{
			if(denominations[i].cnt != 1)
			{
				minDenom = getMin(denominations[i-1].cnt,denom,denomcnt,i,denominations);
				denominations[i].cnt = minDenom;
			}
		}
		else
		{
			denominations[i].cnt = -2;
		}
			
	}
	return minDenom;
}

int _tmain(int argc, _TCHAR* argv[])
{
	int arr[3]={1,2,4};
	int mindenomCnt = FunmindenomCnt(7,arr,3);
	return 0;
}

}

- gopi.komanduri May 31, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static int[] MergeArrays(int[] a, int[] b) {
		if(b==null)
			return a;
		int m = 19;  // number of elements in a
		int n = 9; // number of elements in b
		int x;
		while(m>=0 || n>=0){
			x=m+n+1;
			if(a[m]>b[n]){
				a[x] = a[m];
				a[m]=-1; m--;
			}else{
				a[x] = b[n];
				n--;
			}
			
			if(m<0){
				while(n>=0){
					a[n]=b[n];
					n--;
				}
			}
			if(n<0){
				break;
			}
		}
		
		return a;
		
	}

swetha reddy parava

- Anonymous September 23, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

this is answer for different quesstion! please ignore

- Anonymous September 23, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

sorry, posted code for some other question!!

swetha reddy parava

- Anonymous September 23, 2013 | 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