Robinhood Interview Question

string manipulation, dynamic programming / optimization