Given a 2D grid of letters and a target word, determine if the word can be formed by sequentially connecting letters in adjacent cells. The word can only be constructed by using horizontal or vertical neighboring cells, and each cell can be used at most once.
Your task is to implement the function isWordExist(), which takes a 2D board and a word as input parameters. The function should return true if the word can be formed from the board, and false otherwise.
Example 1
Input: board = {{a,b,c,e}, {s,f,c,s}, {a,d,e,e}}, word = "abcd"
Output: 0
Explanation: The board is- a b c e , s f c s , a d e e. The word "abcd" cannot be formed because there is no adjacent path that includes the letter 'd' after 'c'. Therefore, the output is 0 (false).
Example 2
Input: board = {{a,b,c,e}, {s,f,c,s}, {a,d,e,e}}, word = "see"
Output: 1
Explanation: The board is- a b c e , s f c s, a d e e. The word "see" can be constructed by using the adjacent cells: Starting at (2,3) -> 'e', (2,2) -> 'e', and (1,3) -> 's'. Hence, the output is 1 (true).
Sign in to write, run, and submit your solution against the full test suite.