Solve two string problems | Amazon Interview Question