Click here to Skip to main content
15,886,799 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Input - Output
Eg -3217 -4477
147 - 174
160 - 174

What I have tried:

1) If all digits sorted in descending order, then output is always “Not Possible”. For example, 4321.
2) If all digits are sorted in ascending order, then we need to swap last two digits. For example, 1234.
3) For other cases, we need to process the number from rightmost side (why? because we need to find the smallest of all greater numbers)
Posted
Updated 16-Aug-16 19:48pm

1 solution

This is HomeWork, so it is your task to produce a program.

When you ask someone else a question about your HomeWork, at least post the real statements of the problem. It will avoid crazy situations like this one, where your statements have 5 contradictions or inconsistencies.

Ex: for 4321, I don't see why 4327 or 4477 wouldn't be a valid answer.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900