Ad
  • Custom User Avatar

    This is an issue

  • Custom User Avatar

    Description says the function signature is

    fun findEscapeRoute(trail: Trail) : Unit
    

    but in initial code it's

    fun findEscapeRoute(trail: Trail?): String
    

    The signature in initial code also implies two things:

    • null can be passed inside findEscapeRoute
    • there must be at least a path (because String cannot be null)

    which are incompatible with each other (findEscapeRoute(null) obviously has no exit).

    (Also, Unit is definitely wrong here)

  • Custom User Avatar

    Duplicate

  • Custom User Avatar

    You should add some random tests

  • Default User Avatar

    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.