Help me in solving ALTTAB problem

My issue

My code

#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
#define nl "\n"
#define yes cout <<"YES" << nl
#define no cout << "NO" << nl
#define PI 3.141592653589793238
int main() {
	// your code goes here
	    int n;
	    cin>>n;
	    vector<string>S(n);
	    string ans="";
	    for(int i=0;i<n;i++)
	         cin>>S[i];
	     unordered_set<string>hashset;
	     
	     for(int i=n-1;i>=0;i--)
	     {
	        int len=S[i].length();
	        string suffix=S[i].substr(len-2,2);
            hashset.insert(S[i]);
	     }
    for(auto it : hashset)
    {
        ans+=(it[it.size()-1]);
        ans+=(it[it.size()-2]);
    }
	     for(int i=ans.size()-1;i>=0;i--)
         {
             cout<<ans[i];
         }
	  
	
	return 0;
}

Problem Link: ALTTAB Problem - CodeChef

Can anyone explain why this code is not passing some test cases?
I tried storing all strings in unordered map and then storing last 2 suffixes in array. then printing the array but all test cases are not accepted.

the thing is unordered set does not always stores strings in reverse order that is why u r getting wa for rest of the test cases bcozz by using unordered set u r not ensuring the order of strings. …try it using simple set it will give ac.