Find a Similar Number We consider two integers to be similar if, when written in decimal, have the same length, and if we compare characters in any two positions for both decimal strings, the comparison results (less, equal or greater) must be the same in both strings.

Formally, for two number that can be written as decimal strings \$a_1a_2\cdots a_n\$, \$b_1b_2\cdots b_m\$, they're similar if and only if \$n=m\$ and \$a_i&lt;a_j\ \leftrightarrow b_i&lt;b_j\$ (\$\leftrightarrow\$ means if and only if) for all \$ i,j \in [1,n]\$.

For example, 2131 and 8090 are similar. 1234 and 1111, 1234 and 4321 are not similar.

The challenge

For a given positive integer, find a different non-negative integer similar to it. You can assume at least one such integer exists.


Your implementation shouldn't be too inefficient. It must be at least able to pass the samples in around one hour on an average computer. (If it doesn't end in a few seconds, consider providing a screenshot running it)
Your code can take the input and output as integers, strings or lists of digits. Standard loopholes are forbidden.


Since this is a code-golf, the shortest code in bytes wins!

Examples

It's (quite) possible to have different outputs on these inputs as long as inputs and outputs are different and similar.

1 - 0
3 - 9
9 - 1
19 - 23
191 - 121
1111 - 2222 (0 is not considered valid)
2020 - 9393
2842 - 1321
97892 - 31230
113582 - 113452
444615491 - 666807690
87654321000 - 98765432111
98765432111 - 87654321000
526704219279 - 536714329379
99887766553210 - 88776655443210


Sample inputs as a list:

1,3,9,19,191,1111,2020,2842,97892,113582,444615491,87654321000,98765432111,526704219279,99887766553210
Python 3, 58 52 bytes



lambda n:[9-(9in n)-sum(x&gt;d for x in{*n})for d in n]


Try it online!

Input: The number n, as a list of digits.
Output: A similar number, as a list of digits.

-6 bytes thanks to @xnor!

How:
Reverses the list of unique digits, then maps them to 9,8,7,... or 8,7,6,... depending on whether n contains the digit 9 or not.
For example:

               | n = 1827 | n = 7899
Reverse unique |   8721   |   987
Maps to        |   9876   |   876
Results        | m = 6978 | m = 6788


Old solution

Python 3, 80 bytes



f=lambda n,i=9:(i in n)^(i-1in n)and[[d,d^i^~-i][i-2&lt;d&lt;=i]for d in n]or f(n,i-1)


Try it online!

Input: The number n, as a list of digits.
Output: A similar number, as a list of digits.

-1 byte thanks to @KevinCruijssen!

How
The solution tries to find a pair of consecutive digits \$(i-1,i)\$ such that one digit appears in \$n\$, and the other doesn't. It then replaces all occurrences of one digit with the other.
The pair of digits are searched from \$(8,9)\$ downward, in order to discourage replacing 1 with 0.