Google Phone Screen Round
Anonymous User
2040

I got a mail from recuiter if I am interested in open positions because I took google foobar. They gave me enough time to prepare and when I was comfortable I took the call for interview.

I was interviewed on 8th Jan and the interviewer asked me these two questions.

  1. Imagine an array class with only 3 operations GetAt(), SetAt() and SetAll(). Implement all the methods as O(1).
  2. Given denominations D and a max value MAX, find the smallest set of coins that can exactly construct any value 1 <= n <= MAX.

**The explanation goes like this.
D is a vector, sorted increasing, which describes the monetary system; e.g. {1, 5, 10, 25} for a U.S. penny, nickel, dime, quarter.
MAX is in the same units as D.
The output should be a vector of the same order as D, where each coefficient is how many of that coin you have. "Smallest set" refers to the total number of coins in the set. Some inputs may have multiple equally good answers; you may choose any such answer.

The wasn't able to solve any of those. I provided solutions but they were not up to the mark.
The first one is pretty easy.

Edit:
For the second question I came up with a approach which i would like to share:

public int[] minHeap(int[] denominations,int max){
	int res[]=new int[deno.length];

	for(int i=0;i<deno.length-1;i++) {
			res[i]=deno[i+1]-deno[i];
	}

	res[deno.length-1]=max/deno[deno.length-1];

	return res;
}

Is that correct? Let me know.

Comments (10)