leonid.ge
BAN USER 0of 0 votes
AnswersWrite a function that receives string with decimal number (i.e. all characters are decimal digits) and prints the sum of all possible substringnumbers, example:
 leonid.ge in UK
sum(“123”) = 123 + 12 + 23 + 1 + 2 + 3 = 167 Report Duplicate  Flag  PURGE
Credit Suisse Software Developer Algorithm  1of 1 vote
AnswersThere are three closed doors. Behind two of them there are donkeys, behind the third one there is a MercedesBenz. (Your task is to get the Mercedes, not the donkey).
 leonid.ge in United States
You are asked to choose one of the doors. Once you have chosen, they open one of the remaining two doors with the donkey. Now there are two doors left: one you chose and the other one. To maximize your chance of getting the Mercedes, should you keep your choice or switch to the other door? Report Duplicate  Flag  PURGE
xyz Software Developer Brain Teasers
Yes, this is possible for the duck to escape and the duck should use the singularity when it and the fox are both on the diameter line of the circle.
The optimal strategy for the fox is as follows
(assuming both fox and duck can accelerate to their maximum speed and stop instantly):
1. When the duck is on the diameter line from fox to center of pond:
a. If the duck is between the center and the fox  don't move
b. If the duck is behind the center  move around the pond (to either side).
2. If the duck is not on the diameter line from fox to center of the pond  move to the corresponding side which is closer to the duck.
Now the duck's task is to swim further and further away from the fox, while avoiding fox to switch direction of its run.
Beginning: duck in the centre, fox doesn't move.
Duck starts moving away from the fox.
Fox starts moving around the pond, say, to the right.
Duck keeps moving away from the centre and more and more to the left in a spiral movement, while keeping the angle foxcenterduck always slightly less than 180 degrees.
In this situation the fox will continue running in the same direction, the duck will go further and further away from the center while staying nearly opposite to the fox.
When the duck reaches the edge of the pond, the fox will be nearly on the other side.
(By the way: even if the fox will switch the direction, it will not help him, as the duck will always be able to maintain the angle close to 180 degrees)
After three red balls moved to green bag we have:
Bag1 Bag2
7R 10G+3R
There are 8 possibilities to choose 3 balls from bag2 (which contains 10G+3R):
1. GGG
2. GGR
3. GRG
4. RGG
5. RRG
6. RGR
7. GRR
8. RRR
Each possibility is equally probable, so:
P(choosing 3G) = P(choosing 3R) = 1/8
P(choosing 2G+1R) = P(choosing 1G+2R) = 3/8
So after moving three balls from bag2 to bag1 we have the following possible configurations with their probabilities:
Bag1 Bag2
10R 10G (we moved 3R) P = 1/8
9R+1G 9G+1R (we moved 2R+1G) P = 3/8
8R+2G 8G+2R (we moved 1R+2G) P = 3/8
7R+3G 7G+3R (we moved 3G) P = 1/8
As we can see, the probabilities are completely symmetrical, so the answer is:
"None of the bags is likely to have more of the number of balls of the other color".

leonid.ge
July 31, 2015 Open Chat in New Window
I wrote such a dynamic programming implementation:
But when I tested it later I realized that it does not avoid duplicate substring. For example, for "123" it processes the following substrings: 123 12 1 2 23 2 3. As we can see, substring '2' appears twice. Is there a way to fix this algorithm to avoid duplicates without storing all possible substrings in a set?
 leonid.ge May 04, 2018