GoDaddy Interview Question
Software Engineer / DevelopersCountry: United States
Interview Type: Phone Interview
we can't use 0 as first digit as it wont appear in Calculator and we it will become 7 digit number if we use 0!!
so in my opinion answer should be = 6*7^3 / 9*10^7
That's about right, but as ashutosh141 noted, we might have to modify the formula a bit if leading 0s aren't allowed. We also have to ask whether 6s really look like 9s upside down (in some fonts they do; in others they don't). Of course some of the other digits might not look the same upside down either (do 2s or 5s, for example? Not in the font I'm using now).
Out of 10 digits, we have only 3 digits which look the same as they are upside down.
So, for 1 digit number, probability of getting a digit which will look same after flipping it upside down is = 3/10
Now, for n digits we have n independent events:
so the total probability for n digits:
P = (3/10)^n
For n = 2, P = (3*3)/(10*10) = 3/50 = 0.06
Correct me if I'm wrong.
You're ignoring the fact that the number has to be a palindrome.
The answer is (3/10)^n/2 (1/10)^n/2
It's not the number of digits that look the same upside down that's important, it's the number of digits that look like some digit (itself or some other digit) when upside down. This number really depends on the font being used. If there are k such digits (and k is even), the formula will be k^(n/2) / 10^n (as anonymous already suggested).
Condition for digit combination to appear same when inverted :
a) for every 6 at distance x from left there must be a 9 at distance x from right and vice versa. [ x < 4 ]
b) rest of the digits should be 0,1 or 8.
Now solve it case by case i.e using 0 time 6 and 9, 1 time 6 and 9, two times 6 and 9 ....
//Following is INCORRECT Approach
Number must be formed by 0,1,8 to look same on both sides.
=> Total number of 8 digit combinations possible using 0,1,8 = 3^8
=> Total number of 8 digit combinations = 10^8
Answer = (3^8)/ (10^8)
Ok, but 619 != 916
=>6 and 9 both should be at same distance from beginning and end and we have to use them same number of times.
So this is actually not that easy ;), just need to handle it case by case i.e. 6 and 9 appears :
0 time
1 time
2 times
3 times ...
a) case where 6/9 appear only once in first four digits: 2*3^6*4
b) case where 6/9 appear two times in first four digits: 2^2*3^4*6
c) case where 6/9 appear 3 times in first four digits: 2^3*3^2*4
d) case where 6/9 appear 4 times in first four digits: 2^4
e) case where 6/9 donot appear : 3^8
sum of (a, b, c, d, e)/ 10^6
_ _ _ _ | _ _ _ _
first spot can take values 1,6,8,9
2nd, 3rd,4th spot can take values 0,1,6,8,9
if any spot takes a 6 or 9, the corresponding spot from back will take 9 or 6 respectively.
therefore ans is
4/9 * 5/10 * 5/10 * 5/10 * 1 * 1 * 1 * 1 = 1/18
number has to be palindrome. 0 can't be used at first place.
Using 1,2,5,8 at first place and 0,1,2,5,8 at any other places, we have our interested space as num= 4*5*5*5. Our total space is den= 9*(10^7).
Hence, answer = (num/den)
P.S: the number has to look exactly alike, as in have same value.
if we fill first 4 locations with any of 7 numbers {0,1,2,5,6,8,9}. Rest of the 4 locations in a valid number will be filled by(in corrosponding digit) {0,1,2,5,9,8,6}. Hence, total number of valid 8 digits numbers 7^4/10^8.
- curious March 05, 2013