Meta interview question

Two coding tasks: first one about strings, second one about binary tree