Make Maximum Number

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

Input format :
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 format :
The maximum Number that is formed using the digits present in the linked list.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
Constraints:
1 <= N  <= 10^6
0 <= data <= 9

Time Limit: 1sec
Follow Up:
Can you do this in O(N) time and constant space?
CodingNinjas
author
2y

Approach :

1) Traverse the linked list from start to end and make frequency array of all digits (0-9) present in the linked list.

2) Make the string starting from the maximum of digits (0-9) present in...read more

CodingNinjas
author
2y
Sorting

Traverse in the linked list and store the elements in the vector or array, then sort the array or vector and then reverse the array or vector, return the number as string formed using the digit...read more

CodingNinjas
author
2y
Making Frequency Array

Traverse the linked list from start to end and make frequency array of all digits (0-9) present in the linked list and make the string starting from the maximum of digits (0-9) p...read more

Add answer anonymously...
DE Shaw Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter