Data Structures & AlgorithmsVery hardProduct Company SDE · ICPC regional

Problem: Arrange the numbers 3, 30, 34, 5, 9 so that their decimal concatenation is the largest possible number. What is that largest number?

  1. A. 9534303
  2. B. 3430953
  3. C. 9533430
  4. D. 9534330

Correct answer: D. 9534330

Sort with the comparator 'a before b if a + b > b + a': 9, 5, 34, 3, 30 → 9534330 (since '330' > '303'). A plain descending string sort puts 30 before 3 (9534303), sorting by numeric value gives 3430953, and putting 3 before 34 gives 9533430.

More Coding Interview Problems questions

Exams that ask this topic