C3 AI interview question

This LC medium question: https://leetcode.com/problems/longest-arithmetic-subsequence/. Was pretty difficult and I initially struggled with it before getting the optimal answer