Amazon interview question

Q1. Based on the string. Q2. This is also based on string