Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Minimum sum

Medium Acceptance 17.14% Points 30.00

Given an array arr[] where each element is in the range [0, 9], the task is to find the minimum possible sum of two numbers that can be formed using the elements of the array. All digits in the array must be used to form the two numbers. The result should be returned as a string without leading zeros.

Examples
Example 1

Example 1

Input: arr[] = [6, 8, 4, 5, 2, 3]

Output: "604"

Explanation: The minimum sum is formed by numbers 358 and 246.

Example 2

Example 2

Input: arr[] = [5, 3, 0, 7, 4]

Output: "82"

Explanation: The minimum sum is formed by numbers 35 and 047.

Hints
Hint 1
Expected Time Complexity: O(n log n)
Hint 2
Expected Auxiliary Space: O(n)
Constraints
  • 1 <= arr.size() <= 10^6
  • 0 <= arr[i] <= 9
Companies
Adobe Google Goldman Sachs
Topics
Array Sorting Algorithms
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions