Index sum
Index sum easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Index sum easy Time Limit: 2 sec Memory Limit: 128000 kB
Last updated
Problem Statement:
Given an array a of n integers. Find the maximum value of (i + j) such that 1 ≤ i < j ≤ n and a[i] = a[j]. Input The First line of the input contains n. The next line contains n space-separated integers.
Constraints 1 ≤ n ≤ 105 1 ≤ a[i] ≤ n Output Output a single integer denoting maximum sum. Example Input: 6 2 3 1 2 3 5
Output: 7
Explanation: for 2 => i = 1, j = 4 => i+j = 5 for 3 => i = 2, j = 5 => i+j = 7
link: