Solve two string DP/hash problems | Amazon Coding Question