Amazon Coding Question : Arithmetic Progression