Friday, June 14, 2013

Google Code Jam 2009, Round 1C, Problem A: All Your Base

Here is a nice summary of the approach to this problem.
The above problem statement, requires the output to be the minimum possible number. The first step is to understand that the number would be smaller if you take the smallest possible 'Base System' for the number. To find the base system that you want, you would have to find the number of unique symbols in the input string. If there are 2 'Unique' symbols in the string, take it as 'Base 2' system. If there are 10 unique symbols, take it as 'Base 10 (Decimal)' system.....and so on. Since the 'Unary System' is not used, ignore that. 
After that, we need to find how we can make the sum, as minimal as possible. Since we don't know which digit stands for what, we have to make a decision for each symbol, so as to make the number, as small as possible. Since the left most digit carries more weight, this digit should be multiplied by the smallest digit. But since the left-most digit can't be zero (0), make it '1'. Use the Zero (0) for the second left-most digit (if there is 2nd digit in the number). Then use '2' for the third left most digit (if it is unique), '3' for the 4th left most digit (if it is unique)..and so on, unitl the end of the string with symbols. 
^^

No comments:

Post a Comment