is_negative false if xis_negative -xtrue [while trues append (chr(ord(' ' ) // if = break adds the negative sign back if is_negative return ('-if is_negative else '''joinreversed ( )def string_to_int ( )return functools reduce lambda running_sum crunning_sum string digits index ( ) [ [ ='-':] (- if [ ='-else base conversion in the decimal number systemthe position of digit is used to signify the power of that digit is to be multiplied with for example" denotes the number the base number system generalizes the decimal number systemthe string "ak- ak- "where <ai bdenotes in base- the integer ak- bk- write program that performs base conversion the input is stringan integer and another integer the string represents an integer in base the output should be the string representing the integer in base assume < < use "ato represent "bfor and "ffor (for exampleif the string is " " is and is then the result should be " "since hintwhat base can you easily convert to and fromsolutiona brute-force approach might be to convert the input to unary representationand then group the as multiples of etc for example( ) ( ) to convert to base there are two groups of and with three remainingso the result is ( ) this approach is hard to implementand has terrible time and space complexity the insight to good algorithm is the fact that all languages have an integer typewhich supports arithmetical operations like multiplyadddividemodulusetc these operations make the conversion much easier specificallywe can convert string in base to integer type using sequence of multiply and adds then we convert that integer type to string in base using sequence of modulus and division operations for examplefor the string is " " and then the integer valueexpressed in decimalis the least significant digit of the result is mod and we continue with / the next digit is mod which we denote by 'awe continue with / since mod and / the final digit is and the overall result is " the design of the algorithm nicely illustrates the use of reduction