Goldman Sachs Interview Question

Dp on strings and binary tree