Meta interview question

Array/string manipulation with optimization (maybe DP?) required to pass all the tests