Adobe Interview Question for Member Technical Staffs


Country: India
Interview Type: In-Person




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

Note that there is a simpler version

We have 10 machines and 1 machine is defective with known defect X-1 vs. The rest have X

We then label them 1, 2, 3.... 10

Then take 1 coin from 1, 2 coins from 2 etc...

If they are all fine then we will see 55X as the weight

But if the weight is 55X - M.

Then find Max J s.t. ((55X - M)-55X)/J = -1

That is the machine #.

Now suppose instead you are dealing with m machines with n defective ones whereas X here no indicates the maximum possible weight of an individual coin, including defects.

Take 1 of machine 1, X+1 of machine 2, (X+1)^2 of machine 3 .... (X+1)^(m-1) of machine m.

Call the weight of this combination T. Then the weight expressed in base X+1 can have each coefficient read off to determine exactly what weight of coin is being generated by that machine.

- Sidharth Ghoshal September 11, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Scanner scanner = new Scanner(System.in);
		try {
			System.out.println("Please enter number of machine: ");
			int n = scanner.nextInt();
			System.out.println("Please enter defected number of machine: ");
			int m = scanner.nextInt();
			System.out
					.println("Please enter standard ouput of a non-defective machine: ");
			int x = scanner.nextInt();
			int[][] machines = new int[n][2];
			for (int i = 1; i <= n; i++) {
				System.out.println("Enter machine number: ");
				int machine = scanner.nextInt();
				System.out.println("Enter machine output: ");
				int output = scanner.nextInt();
				machines[i - 1][0] = machine;
				machines[i - 1][1] = output;
			}
			Map<Integer, List<Integer>> map = new HashMap<Integer, List<Integer>>();

			for (int i = 0; i < machines.length; i++) {
				int[] arr = machines[i];
				if (map.containsKey(arr[1])) {
					List<Integer> list = map.get(arr[1]);
					list.add(arr[0]);
					map.put(arr[1], list);
				} else {
					List<Integer> list = new ArrayList<Integer>();
					list.add(arr[0]);
					map.put(arr[1], list);
				}
			}
			System.out.println("Defective machines are " + map.get(x - 1));
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			scanner.close();
		}

- Kuldeep Singh September 21, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If there are n machines and m of them are defective, we can do following procedure:
1.Label machines from #1 to #n
2.Divide them in sets with each set having m+1 machines.
If n = k*(m+1) + r then there will be k+1 sets with k having exactly m+1 machines and 1 last set having r machines. Remember that r can be at max m (max value of n%(m+1))
3.For each of the k+1 sets, get a coin from each machine from the set. Now, take a coin and do its weight comparison with all other coins. (total m comparisons).
4.If all coins are of same weight, we move to next set. If not, we may get a few coins less heavy and therefore the corresponding machines are defective. If the number of defective machines found in a set is already equal to m, we are done else move to the next set.

=>So, in the above method, we are doing in worst scenario doing max comparisons possible which equals: k*(m) + (r-1). Since, k = n/(m+1) and r = n%(m+1), we can write this in terms of n and m as follows: (n/(m+1))*m + n/(m+1) - 1

- ashu1.220791 October 17, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Its about choosing the right number for identifying the machines. Lets say machines are numbered from 1....to...10.

Start picking Fibonacci numbers of coins from each machine. For example
Machine1 : 1
Machine2 : 2
Machine3 : 3
Machine4 : 5
Machine5 : 8
Machine6 : 13
......And so on.

Total weight of coins will tell you the combination of Fibonacci numbers.
lets say number increased or decreased by
5 then defective coins belongs to 3,2
similarly diff 8 (5,3) ,13(8,5) and so on.

- engineous.sumit December 22, 2015 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

engineous.sumit - Can you elaborate on the answer with an example?

- sachin.kodagali February 11, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
int n = 10; // Number of machines
int actualWeight = 354; // Actual weight of all coins
int temp, diff, totalWeight = 0;
List<Integer> lst = new ArrayList<Integer>();
lst.add(1);
lst.add(2);
for (int i = 2; i <= n; i++) {
temp = lst.get(i - 2) + lst.get(i - 1);
lst.add(temp);
}
for (int j = 0; j < lst.size(); j++) {
totalWeight = totalWeight + lst.get(j);
}
diff = totalWeight - actualWeight;
diff = diff * 2;
System.out.println(diff);
loop: for (int i = 0; i < lst.size(); i++) {
for (int j = lst.size() - 1; j >= 0; j--) {
if (diff == (lst.get(j) + lst.get(i)) && j != i) {
System.out.println("Defective machines are: " + i + " & "+ j);
break loop;
}
}
}
}

- Anonymous March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int n = 10; // Number of machines
int actualWeight = 354; // Actual weight of all coins
int temp, diff, totalWeight = 0;
List<Integer> lst = new ArrayList<Integer>();
lst.add(1);
lst.add(2);
for (int i = 2; i <= n; i++) {
temp = lst.get(i - 2) + lst.get(i - 1);
lst.add(temp);
}
for (int j = 0; j < lst.size(); j++) {
totalWeight = totalWeight + lst.get(j);
}
diff = totalWeight - actualWeight;
diff = diff * 2;
System.out.println(diff);
loop: for (int i = 0; i < lst.size(); i++) {
for (int j = lst.size() - 1; j >= 0; j--) {
if (diff == (lst.get(j) + lst.get(i)) && j != i) {
System.out.println("Defective machines are: " + i + " & "+ j);
break loop;
}
}
}

- Anonymous March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

int n = 10; 				// Number of machines
		int actualWeight = 354; 	// Actual weight of all coins
		int temp, diff, totalWeight = 0;
		List<Integer> lst = new ArrayList<Integer>();
		lst.add(1);
		lst.add(2);
		for (int i = 2; i <= n; i++) {
			temp = lst.get(i - 2) + lst.get(i - 1);
			lst.add(temp);
		}
		for (int j = 0; j < lst.size(); j++) {
			totalWeight = totalWeight + lst.get(j);
		}
		diff = totalWeight - actualWeight;
		diff = diff * 2;
		System.out.println(diff);
		loop: for (int i = 0; i < lst.size(); i++) {
			for (int j = lst.size() - 1; j >= 0; j--) {
				if (diff == (lst.get(j) + lst.get(i)) && j != i) {
					System.out.println("Defective machines are: " + i + " & "+ j);
					break loop;

- Anonymous March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		int n = 10; 				// Number of machines
		int actualWeight = 354; 	// Actual weight of all coins
		int temp, diff, totalWeight = 0;
		List<Integer> lst = new ArrayList<Integer>();
		lst.add(1);
		lst.add(2);
		for (int i = 2; i <= n; i++) {
			temp = lst.get(i - 2) + lst.get(i - 1);
			lst.add(temp);
		}
		for (int j = 0; j < lst.size(); j++) {
			totalWeight = totalWeight + lst.get(j);
		}
		diff = totalWeight - actualWeight;
		diff = diff * 2;
		System.out.println(diff);
		loop: for (int i = 0; i < lst.size(); i++) {
			for (int j = lst.size() - 1; j >= 0; j--) {
				if (diff == (lst.get(j) + lst.get(i)) && j != i) {
					System.out.println("Defective machines are: " + i + " & "+ j);
					break loop;
				}
			}
		}
	}

- Tarun March 16, 2016 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void main(String[] args) {
		int n = 10; 				// Number of machines
		int actualWeight = 354; 	// Actual weight of all coins
		int temp, diff, totalWeight = 0;
		List<Integer> lst = new ArrayList<Integer>();
		lst.add(1);
		lst.add(2);
		for (int i = 2; i <= n; i++) {
			temp = lst.get(i - 2) + lst.get(i - 1);
			lst.add(temp);
		}
		for (int j = 0; j < lst.size(); j++) {
			totalWeight = totalWeight + lst.get(j);
		}
		diff = totalWeight - actualWeight;
		diff = diff * 2;
		System.out.println(diff);
		loop: for (int i = 0; i < lst.size(); i++) {
			for (int j = lst.size() - 1; j >= 0; j--) {
				if (diff == (lst.get(j) + lst.get(i)) && j != i) {
					System.out.println("Defective machines are: " + i + " & "+ j);
					break loop;
				}
			}
		}
	}

- Tarun March 16, 2016 | 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