Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

Given the numbers 3, 30, 34 and 5, arrange them in some order and concatenate the decimal strings. What is the largest number that can be formed?

  1. A. 343053
  2. B. 330345
  3. C. 534303
  4. D. 534330

Correct answer: D. 534330

Sort by comparing a+b against b+a, since the best concatenation places x before y exactly when xy >= yx. Plain numeric sorting or sorting by first digit produces a smaller concatenation.

More Coding Interview Problems questions

Exams that ask this topic