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?
- A. 9534303
- B. 3430953
- C. 9533430
- 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
- Problem: Minimum number of jumps to reach the last index of [2, 3, 1, 1, 4] when from index i you may jump up to a[i] steps forward. What…
- Problem: Find the k-th largest element of [3, 2, 1, 5, 6, 4] for k = 2 (1-indexed among values, with duplicates counted separately).
- Problem: The intervals [1,3], [2,4], [3,6], [7,8], [5,9], [8,10] are given. What is the minimum number of intervals to remove so that the…
- Problem: Find the number of unique triplets (as value sets) that sum to zero in [−1, 0, 1, 2, −1, −4].
- Problem: How many substrings of "eceba" contain exactly 2 distinct characters?
- Problem: For the array [3, 1, 4, 1, 5, 9, 2] and window size 3, compute the sum of the minimum of every contiguous window.