Beta

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.

Fundamentals
Graph Theory

Stats:

CreatedFeb 12, 2019
PublishedFeb 12, 2019
Warriors Trained164
Total Skips14
Total Code Submissions146
Total Times Completed27
Kotlin Completions27
Total Stars0
% of votes with a positive feedback rating77% of 15
Total "Very Satisfied" Votes10
Total "Somewhat Satisfied" Votes3
Total "Not Satisfied" Votes2
Total Rank Assessments13
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • yujinred Avatar
Ad