Help me in solving ALTTAB problem

My issue

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n;cin>>n;
	vector<pair<int,string>> v;
	map<string,int> mp;
	int j=0;
	for(int i=0;i<n;i++){
	    string s;cin>>s;
	    mp[s]=i;
	}
	for(auto it:mp){
	    v.push_back({it.second,it.first});
	}
	sort(v.begin(),v.end());
	string s="";
	for(auto it:v){
	    string temp=it.second;
	    int ln=temp.size();
	    s += temp[ln-2];
	    s += temp[ln-1];
	}
	reverse(s.begin(),s.end());
	cout<<s;
	return 0;
}

Problem Link: ALTTAB Problem - CodeChef

all correct just a little change, add temp[ln-1] first instead of temp[ln-2] to ā€˜sā€™ as you reversed the final string.( check output format )