β Index sum
Index sum easy Time Limit: 2 sec Memory Limit: 128000 kB
```java
import java.io.*; // for handling input/output
import java.util.*; // contains Collections framework
// don't change the name of this class
// you can add inner classes if needed
class Main {
public static void main (String[] args) {
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int max=0;
HashMap<Integer,Integer>hm=new HashMap<>();
for(int i=0;i<n;i++){
int a=sc.nextInt();
if(hm.containsKey(a)){
max=Math.max(max,i+hm.get(a)+2);
hm.remove(a);
hm.put(a,i);
}else{
hm.put(a,i);
}
}
System.out.println(max);
}
}
```Last updated