You are given a tuple of integers $B=(b_1,b_2,\ldots,b_n)$.
Find $(a_1,a_2,\ldots,a_n)$ - a permutation of $(b_1,b_2,\ldots,b_n)$ - that maximizes $a_1^{a_2^{\ldots^{a_n}}}$.
For example -
If $B=(5, 6, 4)$, then the answer is $(4 ,5, 6)$.
If $B=(2,3)$, then the answer is $(3,2)$.
Note - Power is calculated in order given below
$a_1^{(a_2^{(\ldots^{a_n})})}$.
Sharing the answer for audience-
Let answer be A. All the 1s to A and remove them from Seq. i.e If Seq is 4,3,2,1,1 then after step 2 seq will be 2,3,4 and A = 1,1
if first element in Seq is 3 and second element is 2 then remove both from Seq and add 2,3 to A
Add rest of the elements from Seq to A.
Reverse the numbers in A
Let me know if you find anything wrong in given solution.