Description
Solutions
Submission
Cave Advanture

Embark on a perilous adventure with a group of brave explorers as they venture into the unknown depths of a mysterious cave! The cave is divided into a rectangular map with N rows and M columns, representing treacherous levels and chambers. The explorers' quest begins at the entrance (0, 0) and their ultimate goal is to reach the exit in the farthest corner (N-1, M-1).

As they navigate through the cave, they'll encounter chambers marked with '!' which are safe to explore, and others marked with 'x' which are treacherous and impossible to pass through due to debris and danger. The explorers can move left, right, or climb down to the next level, but beware - climbing up is too risky, and they can never re-enter a chamber they've already visited!

Their mission is to explore as many chambers as possible without backtracking or entering unsafe areas outside the map. If they can't reach the exit, the expedition will be canceled due to safety concerns.

Can you help the explorers chart their course and find the maximum number of chambers they can explore on their journey to the exit? If not, return -1 to cancel the expedition.

See "Problem Source" below for reference 👇👇

Example 1:

Input:  A = ["..0.", "...0", "....","0..."]
Output: 9
Explanation:
See the example image for one of the longest paths:

Example 2:

Input:  A = [".0...", ".0...", "...0."]
Output: -1
Explanation:
They won't be able to reach the exit because they need to climb :(

Example 3:

Input:  A = ["......", ".0000.", "...0..", "...0.0", "......"]
Output: 14
Explanation:
The longest route is one-of-a-kind
Constraints:
    N/A
Thumbnail 0
Thumbnail 1
Testcase

Result
Case 1

input:

output: