問題文を言い換えると、 の並び替えのうち、辞書順で最大のものが より辞書順で小さいか、ということになります。 の並び替えで辞書順最大のものは を逆順ソートしたものなので、これと の大小比較をすることにより、この問題を解くことができます。
c++, Python での実装例を以下に示します。
#include<bits/stdc++.h>
using namespace std;
int main(){
string s, t; cin >> s >> t;
sort(s.rbegin(), s.rend());
if(s < t){
cout << "Yes" << "\n";
}else{
cout << "No" << "\n";
}
}s = list(map(str, input()))
t = list(map(str, input()))
s.sort(reverse = True)
print("Yes" if s < t else "No")