Data Structures & AlgorithmsVery hard

Arrange the numbers 3 30 34 5 9 in some order and concatenate their decimal digits. What is the LARGEST number that can be produced?

  1. A. 3430953
  2. B. 9534330
  3. C. 3593034
  4. D. 0334359

Correct answer: B. 9534330

Sort with the comparator that puts x before y when x+y > y+x, which compares the two possible concatenations directly. Sorting numerically descending places 30 and 3 wrongly, since 330 beats 303.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic