Longest Arithmetic Sequence(LeetCode 1027):

Problem