Solve array and list algorithms | Amazon Coding Question