Google | Phone Screen | Longest Arithmetic Sequence
Anonymous User
2758

Given a binary tree, return the maximum length of the path which is a valid arithmatic progression sequence. A path in the tree starts at the root node and ends at the leaf node. Tree can have multiple valid arithmatic progression sequence paths, return the max length of all.

          2
       /     \
      0       4
    /   \   /    \
  -2    -2 10      6
 /   \           /   \
9    -4         -1    8

Valid AP paths - 2 0 -2 -4
Valid AP paths - 2 0 -2
Valid AP paths - 2 4 6 8

max_len = 4
Comments (8)