Divide the digits
Practice
3 (6 votes)
Algorithms
Basics of greedy algorithms
C++
Greedy algorithms
Problem
82% Success 2383 Attempts 10 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a number \(N\)

You are required to form two numbers \(X\) and \(Y\) such that:

  • The sum of frequency of each digit in \(X\) and \(Y\) is equal to frequency of that digit in \(N\).
  • The sum of numbers \(X\) and \(Y\) must be minimum.

Your task is to determine the minimum possible sum of \(X\) and \(Y\).

Input format

  • The first line contains an integer \(T\) that denotes the number of test cases.
  • For each test case:
    • The first line contains an integer \(N\).

Output format

For each test case, you are required to print the minimum possible sum of \(X\) and \(Y\) in a new line.

Constraints

\(1 \le T \le 10^5 \\ 10 \le N \le 2 \times 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:10
11 votes
Tags:
HashingGreedy AlgorithmsBasics of Greedy AlgorithmsAlgorithms
Points:10
14 votes
Tags:
Basics of Greedy AlgorithmsGreedy AlgorithmsAlgorithms
Points:10
2 votes
Tags:
Basics of Greedy AlgorithmsAlgorithmsGreedy Algorithms