Solve two string DP/hash problems | Amazon Interview Question