Amazon Interview Question

2 leetcode medium level question , one is based on string and one was about hash map related