Amazon Interview Question

technical portion of the interview asked me to create a function