String pyramid transition matrix

  • 0

    I was asked the below question in my Google phone interview.
    Problem: given a list of leaf nodes in a pyramid ,and a map which indicates what's the possible parent node given a left and right node. Return true if the one of leaf node could turn into the root node, Otherwise, return false.

         / \
        X   X
       /\  /\
       X  X  X
      / \/ \/ \
     A   B  C  D
           left:  A     |  B       |      C | D
    right     ---------------------------------
    A             B    | A or C |   D | A
    B             D    |B or C |   A |
    C                              B

    Note:1. If left child is B, right child is A, the parent node could be B or C


  • 0

    Can someone help with pseudo code or algorithm? Thanks.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.