DoorDash | SDE | Tech Phone Interview | 2021
Anonymous User
4385

Q. Compute the total number of operations required to convert one N-ary tree to another.

class TreeNode {
        String key;
        int value;
        List<TreeNode> children;
    }

Tree-1

               a(1)                                                
            /       \                                                          
         b(2)       c(3)                                               
        /     \         \                                                         
      d(4)    e(5)      f(6)      

Tree-2

            a(1)
                \
               c(3)
                   \
                   f(66)

Operations:

  1. b(2) was removed from Tree-1 (Count = 1)
  2. Childrens of b(2) are removed, i.e. d(4) & e(5) (Count += 2)
  3. f(6) was updated to f(66) in Tree-2 (Count += 1)

Total Operations done (Count = 4)

Comments (8)