Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Needs random tests.
Description says the function signature is
but in initial code it's
The signature in initial code also implies two things:
null
can be passed insidefindEscapeRoute
String
cannot benull
)which are incompatible with each other (
findEscapeRoute(null)
obviously has no exit).(Also,
Unit
is definitely wrong here)Duplicate
Improvement for the discription:
One day you had the terrible idea to go outside and hike a mountain. Unfortunately, you stumbled upon a giant bear and now you need to escape FAST.
You are deep in the forest and you have no idea where the exit is. Thankfully the trail is not cyclic and each path splits into only 2 directions (left and right). Some paths might be blocked by rocks or fallen trees. Then you cannot go in that direction. If both paths are blocked, then you're trapped in a dead end where the bear can catch you.
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 paths, left and right. (note that these paths can be blocked, this is denoted by a null). An exit is the goal to escape the bear. There is always an exit, but THERE IS ONLY ONE EXIT.
Thankfully you bought your drone with you to scout for the exit. 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:
fun findEscapeRoute(trail: Trail) : String
Your output should be directions in terms of "l" and "r" concatenated together to form a path to the exit. There is exactly one correct 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.