Escape from the bear!
Description:
One day you made the terrible idea to going outside and hike a mountain. Unfortunately, you stumbled upon a giant bear and you need to escape FAST.
You are deep in the forest and you have no idea where is the exit. Thankfully the trail is not cyclic and each path splits into only 2 directions (left and right). Some path might be blocked by rocks or fallen trees so you can only go in one direction. If both path are blocked, then you're trapped in a dead end where the bear can catch you. However, sometimes
The mountain trail is modelled as following:
class Trail(val type: String, var left: Trail?, var right: Trail?)
The Trail can either be a "crossroad" or an "exit". A crossroad is basically a intersection that has 2 path left and right. (note that these path can be block and this is denoted by a null for left or right). An exit is the goal to escape the bear. THERE IS ONLY ONE EXIT.
Thankfully you bought your drone with you, however, you have to program it yourself. Please program the
fun findEscapeRoute(trail: Trail) : Unit
Your drone can do a scan of the area but it is up to you to find an escape route to the exit given a provided Trail. Your output will be directions in terms of "l" and "r" concatenated together to form a path to the exit. There can only be one unique path for each trail.
For example, if I were to give you a trail like this:
└── crossroad
├── crossroad
| ├── NULL
| └── crossroad
| ├── exit
| | ├── NULL
| | └── NULL
| └── NULL
└── crossroad
├── NULL
└── NULL
then your solution should be
lrl
since you go left at the first crossroad, then right on the second crossroad, and left to reach the exit.
Similar Kata:
Stats:
Created | Feb 12, 2019 |
Published | Feb 12, 2019 |
Warriors Trained | 164 |
Total Skips | 14 |
Total Code Submissions | 146 |
Total Times Completed | 27 |
Kotlin Completions | 27 |
Total Stars | 0 |
% of votes with a positive feedback rating | 77% of 15 |
Total "Very Satisfied" Votes | 10 |
Total "Somewhat Satisfied" Votes | 3 |
Total "Not Satisfied" Votes | 2 |
Total Rank Assessments | 13 |
Average Assessed Rank | 6 kyu |
Highest Assessed Rank | 5 kyu |
Lowest Assessed Rank | 7 kyu |