I know I need to check the digits of each array element but counting digits and comparing digit at a time will increase time complexity a lot.
How to tackle this
How to approach
@simar94.singh you can compare the strings directly by the < operator. It will give the answer according to the lexicographical order.
suppose there are two numbers like 9 and 98
now the biggest number formed can be 998
but your code will give output as 989 because while sorting lexiographically 98 has a bigger value than 9
what you can do is, in the compare functions, check whether a+b is making a bigger number or b+a is making a bigger number. and return the values accordingly.
I hope I have solved your problem now. Please mark your doubt as resolved if you are satisfied.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.