I was reading an article on Longest Arithmetic Progression. The solution given has S(n)=$O(n^2)$. Can't I solve it in $O(1)$ space? To find the three elements, we first fix an element as middle element and search for other two (one smaller and one greater). When we found them we still keep on decreasing left and right to find llap (length of longest arithmetic progression). The other cases left are those where llap is even.. for them I will select i and (i+1)$^{th}$ element as my center two elements of AP and find elements on their right and left satisfying ap. T(n) will still be $O(n^2)$.
Is my approach correct?