Amazon Interview Question

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