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?
- A. 343053
- B. 330345
- C. 534303
- 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
- Problem: Count (possibly overlapping) occurrences of a pattern in a text with KMP. python def kmpcount(t, p): f = [0] len(p); k = 0 for i…
- Problem: Count DISTINCT palindromic substrings by expanding around centres and collecting them in a set. python def distinctpal(s): seen =…
- Problem: Build the suffix array of a string (start indices of suffixes in sorted order) and its LCP array (Kasai's algorithm). python def…
- Problem: A Fenwick tree over a DIFFERENCE array supports 'add v to a[l..r]' and 'read a[i]' in O(log n) (1-indexed, all zeros initially)…
- Problem: Point-update / range-maximum segment tree (iterative, size n = 8). python n = 8; t = [0] (2 n) def upd(i, v): i += n; t[i] = v…
- Mo's algorithm answers q offline range queries on an array of n elements by sorting queries into √n-sized blocks of their left ends. If…