person A: 1 minute
person B: 2 minutes
person C: 5 minutes
person D:10 minutes
Solution below...
of course its possible, otherwise it wouldn't be a very interesting question. the only trick is in realizing that you want to get the two slowest people across together, because otherwise you are wasting too much time. but then once you get them across, how do you not make one of them walk back with the flashlight? well, you just have one of the fast people already there waiting to sprint the flashlight back across.
1. A & B cross. total time: 2 minutes.
C |==========================| A
D | | B
|==========================| flashlight
2. B comes back. total time: 4 minutes.
C |==========================| A
D | |
B |==========================|
flashlight
3. C & D cross. total time: 14 minutes.
B |==========================| A
| | C
|==========================| D
flashlight
4. A comes back. total time: 15 minutes.
A |==========================| C
B | | D
|==========================|
flashlight
5. A & B cross. total time: 17 minutes.
|========= =============| A
| KABOOM! | B
|========= =============| C D
flashlight
another solution which is valid is to have A bring the flashlight back in step 2. it only changes the solution slightly. this is supposed to be a "classic" microsoft interview question but it seems absurdly easy to be a good interview question (especially coupled with the fact that everyone has probably heard it already).
1. A & B cross. total time: 2 minutes.
C |==========================| A
D | | B
|==========================| flashlight
2. B comes back. total time: 4 minutes.
C |==========================| A
D | |
B |==========================|
flashlight
3. C & D cross. total time: 14 minutes.
B |==========================| A
| | C
|==========================| D
flashlight
4. A comes back. total time: 15 minutes.
A |==========================| C
B | | D
|==========================|
flashlight
5. A & B cross. total time: 17 minutes.
|========= =============| A
| KABOOM! | B
|========= =============| C D
flashlight
another solution which is valid is to have A bring the flashlight back in step 2. it only changes the solution slightly. this is supposed to be a "classic" microsoft interview question but it seems absurdly easy to be a good interview question (especially coupled with the fact that everyone has probably heard it already).
No comments:
Post a Comment