Find the Treasure

John, the famous treasure hunter wants to find a treasure in a maze. The maze is represented by 2D array of 0’s and 1’s where 0 means there is a crocodile and he will die if he visits that element and 1 means safe passage. He has to reach to 2 where the treasure is hidden without dying.

Write a program that takes a 2D array and only accepts values as 0,1 and only one 2 and checks if there exists any path that leads him to the treasure without dying?

Expected return value :1
Test case 2:
Input: [[0,0,0],[2,1,1],[0,1,1]]
Expected return value: 0