Amazon Interview Question

coding question, complexity, Test cases