Giving me TLE on leetcode

link to code->https://ide.codingblocks.com/s/649109

link to question->https://leetcode.com/problems/longest-arithmetic-subsequence/

Hello @ikshuldureja130,

The time complexity of your code:

O(n^4 log(n))
n^2 for nested for loops,
log(n) for map find operation and,
extra n^2 times for searching correct pos in map.

You can take the worst case as if

N = 1000 and,
all elements in nums array equals to 0, i.e nums[i] = 0 for 1 <= i <= N
number of operation would be greater than 1e9

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.