Skip to main content

Oracle

Oracle OA-3 2023

Problem Description

Alice has an integer array A of length N. However, due to a virus, some digits in these integers have been replaced by uppercase English letters from 'A' to 'J'.

For example, let us suppose an integer was "1221321", and due to the virus, it is changed to "B2AB3A1". That means some '1's are changed to the character 'B' and some '2's are changed to the character 'A'. However, it is not possible for this integer to be changed to:

  • "BB21321" (where two different digits are changed to a single character 'B')
  • "B22A321" (where the same digit '1' is changed to two different characters)

You have been given the array A after the virus attack. Alice has asked you to decode the integers in this array in such a way that, after decoding, the summation of all integers of the array is minimized. Your goal is to print the minimum possible summation.

Note:

  • You must decode the integers such that no integer contains leading zeros like "001", "0123", etc.
  • There will be at most 10 characters only (A-J).
  • It is guaranteed that an answer exists for every given test case.

Input Format:

This is the input format you must use to provide custom input

  • The first line contains an integer T denoting the number of test cases. T also denotes the number of times you have to run the solve function on a different set of inputs.
  • For each test case:
    • The first line contains a single integer N denoting the size of the array A.
    • The second line contains N space-separated strings denoting elements of array A.

Output Format:

For each test case, print the minimum possible summation.

Constraints:

  • 1 ≤ T ≤ 10^3
  • 1 ≤ N≤ 10^5
  • 1 ≤ ∣A[i]∣ ≤ 91, where A[i] denotes the length of the string A[i].

Example:

Input: N = 2, A = [A1A, 2AB]

Approach:

  • If you decode 'A' = 1 and 'B' = 0, then the array A will become [111, 2101].
  • If you decode 'A' = 1 and 'B' = 0, then the array A will become [111, 210].
  • In this case, the summation of all elements in A will be the minimum possible, which is 321.

Thus, the answer is 321.