Problem Β· Matrix

Search Mysterious Grid πŸ’ͺ

● HardMetaFULLTIMEOA
See Meta hiring insights

You're exploring a mysterious grid filled with ancient symbols, and you possess a set of unique symbols that you seek within this grid. Your mission is to devise a method to search for these symbols amidst the labyrinth of characters. However, there are rules to follow:

  • You can only find a symbol if it can be formed by connecting adjacent characters along a path within the grid.
  • The path may start at any cell and initially must move either from left to right or from top to bottom..
  • You're allowed to change direction once during your search, reversing from left to right or from top to bottom.
  • Your task is to calculate the number of times you encounter these symbols within the grid, following these strict guidelines.

    P.S. For original prompt, pls refer to source image πŸ’›

    Examples
    01 Β· Example 1
    phrases = ["ac", "cat", "car", "bar", "acdc", "abacaba"]
    grid = [["a", "b", "a", "c"], ["x", "a", "c", "d"], ["y", "r", "d", "s"]]
    return = 7
    Unfortunately, we don't have the access to the video mentioned in the example image πŸ₯Ή
    Constraints
    Uknown for now
    More Meta problems
    drafts saved locally
    public int searchMysteriousGrid(String[] phrases, String[][] grid) {
        // write your code here
    }
    
    phrases["ac", "cat", "car", "bar", "acdc", "abacaba"]
    grid[["a", "b", "a", "c"], ["x", "a", "c", "d"], ["y", "r", "d", "s"]]
    expected7
    checking account