Help me in solving ALTTAB problem

My issue

My code

/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		String arr[]=new String[n];
		for(int i=0;i<n;i++){
		    arr[i]=s.next();
		}
		HashMap<String,Integer>map=new HashMap<>();
		String ans="";
		for(int i=n-1;i>=0;i--){
		    if(!map.containsKey(arr[i])){
		        int l=arr[i].length();
		        if(l>=2){
		        ans=ans+arr[i].substring(l-2,l);}
		        map.put(arr[i],1);
		    }
		}
		System.out.println(ans);
	}
}

Problem Link: ALTTAB Problem - CodeChef