Skip to main content

Oracle

Oracle OA 2023 - Decrypt


Alice has an integer array A of size N. Alice saved these integers in her computer, but due to a virus attack, some of the digits of her integers were changed to some characters from uppercase English alphabets 'A' to 'J'. It is known that a unique digit is changed with a unique character.

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.

Task:

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.

Example:

Assumptions:

  • 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.

Function Description:

Complete the function solve provided in the editor. This function takes the following 3 parameters and returns the required answer:

  1. N: Represents the size of the array A.
  2. A: Represents the array A.

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].