Calculating the dp array for each possible position and calculating the max length that ends at a particular index
for ( auto i : v ) { dp [ i . second . second ] = max ( dp [ i . second . second ] , 1 + dp [ i . second . first ] ) ; } int ans = 1 ;