Maximum Number from Linked List Problem Statement
Given a linked list where each node contains a single digit, your task is to construct the largest possible number using these digits.
Objective:
Print the maximum integer that can be formed from the given list of digits.
Input:
The first and only line of each test case consists of linked list elements of length n (separated by space and terminated by -1).
Output:
The maximum number that can be formed using the digits present in the linked list.
Example:
Input:
3 1 4 -1
Output:
431
Constraints:
- 1 <= N <= 106
- 0 <= data <= 9
- Time Limit: 1 second
Note:
You do not need to print anything; it has already been taken care of. Just implement the given function.
Follow-Up:
Can you solve this problem in O(N) time and constant space?
AnswerBot
9d
To find the maximum number that can be formed using the digits present in a linked list.
Traverse the linked list and store the digits in an array
Sort the array in descending order
Concatenate the sorte...read more
Help your peers!
Add answer anonymously...
Top DE Shaw Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in DE Shaw Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app