Update appNew update is available. Click here to update.

Make Maximum Number

Contributed by
Anish De
Last Updated: 23 Feb, 2023
Medium
yellow-spark
0/80
Avg time to solve 18 mins
Success Rate 85 %
Share
18 upvotes

Problem Statement

Given a linked list such that each node represents a digit. Construct the maximum number possible from the given digits.

You just need to print the maximum Integer that can be formed

Detailed explanation ( Input/output format, Notes, Images )
Constraints:
1 <= N  <= 10^6
0 <= data <= 9

Time Limit: 1sec
Sample Input 1 :
 1 2 2 0 9 -1
Sample Output 1 :
 92210
Explanation For Sample Input1:
The digits that are present in the linked list are : (1, 2, 2, 0, 9 )

So the answer is the maximum of all the numbers that are formed using these digits is 92210.
Sample Input 2 :
1 0 0 0 3 -1
Sample Output 2 :
31000
Reset Code
Full screen
Auto
copy-code
Console