That's because both 4900 and 7963 are 4 digit numbers. 4900 came first, so it holds the distinction of being the number with the max length. Therefore, the output is correct.Originally Posted by Afik
You can of course have more complicated "tiebreaker" requirements, e.g., if there is more than one number with the max length, pick the number that also has the max digit sum, but then you're going to have to change your implementation to handle this, e.g., store all the current known numbers with max length in an array, and all the current known numbers with max digit sum in another array, then compute the intersection of the two arrays. So, it can be done, but I'd suggest checking the requirements with your teacher first.