Practice Problem..Codevita...How to approach this problem?

Minimum BidMarks:200

Problem Description

Consider people calling out bids in different number bases at an auction. Find the minimum bid assuming the following:

  1. The bid numbers are in bases that make their respective values minimum.

  2. There is only one minimum value among all the bids.

Constraints

  1. N <= 10

  2. Maximum base = 36

  3. Symbols used for digits: Base 2: 0, 1
    Base 3: 0, 1, 2

    Base 11: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A

Base 36: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z

  1. Face values for symbols: Symbol => Value 0 => 0
    1 => 1
    2 => 2
    ….
    9 => 9
    A => 10
    B => 11
    ….
    Z => 35

Input Format

N different numbers in various bases, with numbers delimited by space

Output

The value in base 10 of the minimum bid.

Test Case

Explanation

Example 1

Input

11 12

Output

3

Explanation

The value of number represented by 11 is least in base 2 and that least value in base 10 is 3. The least value of the representation 12 is in base 3 and is equal to 5. Since 3 < 5, 3 is the lowest bid and is the output.

Example 2

Input

1Z A L0 17

Output

10

Explanation

The least values are:
1Z in base 36: 136+35 = 71
A in base 11: 10
L0 in base 22: 21
22+0 = 462
17 in base 8: 1*8+7 = 15
Hence the least bid is 10.

import java.io.;
import java.util.
;
import java.lang.*;//pow
class FaceValues
{
int len;
public int[] convert(String s)
{
char[] c= s.toCharArray();
len=c.length;
int[] a= new int[len];
int i,j=0;
for(i=0;i<len;i++)
{
//https://www.tutorialspoint.com/how-to-check-if-a-given-character-is-a-number-letter-in-java
if(Character.isDigit(c[i]))
a[j] = Character.getNumericValue(c[i]);
else
{
a[j] = c[i];
a[j] = a[j] - 55;//A=65
}
j++;
}
j–;
return a;
}
int findBase(int[] arrMax)
{
int max=arrMax[0];
for(int i=1;i<arrMax.length;i++)
{
if(max<arrMax[i])
max=arrMax[i];
}
return max+1;
}
}
class LeastBid
{
public static void main(String args[])
{
int a[]=new int[10];
int decimal = Integer.MAX_VALUE;
String str;
int i,j,k,l;
FaceValues values = new FaceValues();
Scanner sc=new Scanner(System.in);
str = sc.nextLine();
String[] array = str.split(" ");
for(i=0;i<array.length;i++)
{
int[] valArr = values.convert(array[i]);//has the face values of element 1
int base = values.findBase(valArr);//to fund base we need to find the max in valArr and add 1
int power=valArr.length;
double sum=0;
for(j=power-1,k=0; j>=0 && k<power; j–,k++)
{
sum = sum+ ( valArr[k]*Math.pow(base,j) );
}
//now i need to find min of the sum
if(sum<decimal)
decimal=(int)sum;
}
System.out.println(“least decimal value:”+decimal);
}
}

1 Like

Thanks…Can u please explain the concept and logic?