Find substring from dictionary concatenation | Amazon Interview Question