Coin Problem

You are given 9 gold coins that look identical. One is
counterfeit and weighs a bit greater than the others, but
the difference is very small that only a balance scale can
tell it from the real one. You have a balance scale that
costs 25 USD per weighing.

Give an algorithm that finds the counterfeit coin with as
little weighting as possible. Of primary importance is that
your algorithm is correct; of secondary importance is that
your algorithm truly uses the minimum number of weightings
possible.

HINT: THE BEST ALGORITHM USES ONLY 2 WEIGHINGS!!!



Coin Problem You are given 9 gold coins that look identical. One is counterfeit and weighs a b..

Answer / pawan jain

1. Divide the coins in 3 groups of 3 coins each
2. Put 2 groups in the weighing scale
3a. If both the groups weigh equal
1. Pick 2 coins from the 3rd group and put in weighing scale
2. If they weigh equal, the 3rd coin is counterfeit.
Else the coin which weigh more is counterfeit
3b. If they do not weigh equal, pick the group with more
weight and do steps 3a1 and 3a2.

Is This Answer Correct ?    40 Yes 13 No

Post New Answer

More C++ Code Interview Questions

Write a program that takes a 3 digit number n and finds out whether the number 2^n + 1 is prime, or if it is not prime find out its factors.

5 Answers   ADP, Amazon, HCL, IBM, Infosys, Satyam, TCS, Vimukti Technologies,


. Write a program using two-dimensional arrays that computes the sum of data in tows and the sum of data in columns of the 3x3 (three by three) array variable n[3][3].

2 Answers   IBM,


An array of size 5X5 is given to us. The elements from 1 to 25 are to be inserted in the array, such that starting from a particular position for an element i, the next element i+1can be inserted only at the mentioned positions (u,v), and if these all positions are occupied then it returns giving a count of how many positions have been occupied in the array: (u,v) = (x+/-3 , y) (u,v) = (x , y+/-3) (u,v) = (x+/-2 , y+/-2). Example: if the starting element is 1 with the given positions (1,2), then next element 2 can be placed at any one of the positions marked with *. _ _ _ _ _ 1 _ _ _ * _ _ _ _ _ _ _ * _ _ * _ _ _ _

0 Answers   Nagarro,


Algorithm in O(2n) Presently we can solve in our hypothetical machine problem instances of size 100 in 1 minute using algorithm A, which is a O(2n). We would like to solve instances of size 200 in 1 minute using algorithm A on a new machine. What is the speed of the new machine should be?

2 Answers   ABC, Qatar University,


U hv to enter a range from a and b and search hw many no. of times a pattern n. occurs between the range a and b. Eg :i/p:enter range :0 100 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 0 to 100:1 Eg :i/p:enter range :100 1000 Enter pattern: 13 o/p: the no. times 13 occurred betwwn 100 to 1000: (in this 13,113,131,132,133…139,213,313,…913 all these will be counted)

0 Answers  






A suduco given & u hv 2 check if it is incomplete(blanks left),or correct or incorrect

0 Answers  


How do I store linked list datas into an array?

1 Answers  


Wrie a function which returns the most frequent number in a list of integers. Handle the case of more than one number which meets this criterion. public static int[] GetFrequency(int[] list)

3 Answers   Nagarro,


PROBLEM #8 The cashier at the counter of a Super Store, Mr. Khazaanchi has the following bundles of rupee cash notes with him: Rs. 1, 2, 5, 10, 50, 100, 500, 1000 A customer comes at his counter with various items that he has shopped. Mr. Khazaanchi totals the item prices and tells the customer his total amount payable. The customer gives Mr. Khazanchi some amount of cash. Find the total number of rupee notes of each denomination (i.e. 1, 2, 5, 10, 50, 100, 500, 1000) Mr. Khazaanchi will have to give to the withdrawer ensuring that the total number of rupee notes are minimum.

1 Answers   AR, ARJ,


What output does the following code generate? Why? What output does it generate if you make A::Foo() a pure virtual function? class A { A() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; class B : public A { B() { this->Foo(); } virtual void Foo() { cout << "A::Foo()" << endl; } }; int main(int, char**) { A objectA; B objectB; return 0; }

0 Answers  


can you please write a program for deadlock that can detect deadlock and to prevent deadlock.

0 Answers  


Perform the functionality of 2-D array through 1-D array and in it the functions to be performed were: (1) Display the array in 2-D format (2) Display a particular element (3) Display a particular row (4) Display a particular column

1 Answers   Nagarro,


Categories