Sollicitatiegesprek voor de functie Senior Python Developer



Given a very long string composed of numbers as characters, find the four character substring that has the largest multiple. For example, given the string "809723", the two char substring with the largest multiple is "97", having a multiple 9*7 = 63.


Antwoorden op sollicitatievragen

4 antwoorden


max([functools.reduce(operator.mul, data[i-4:i]) for i in data if i > 3])

guych op


max([functools.reduce(operator.mul, data[i-4:i]) for (i, e) in enumerate(data) if e > 3])

guych2 op


def largest_2str_multipler(a): l = len(a) m = int(a[0])*int(a[1]) for x in range(1,l-1): if m < int(a[x])*int(a[x+1]): m = int(a[x])*int(a[x+1]) return m

taleb op


import re, sys input_string = input("Please enter a string with all digits: ") largest_multiple = 0 if not re.match('^[0-9]+$', input_string): print("Invalid Input") sys.exit() for i in range(0,len(input_string)-3): multiple = int(input_string[i]) * int(input_string[i+1]) * int(input_string[i+2]) * int(input_string[i+3]) if multiple > largest_multiple: largest_multiple = multiple largest_multiple_string = input_string[i:i+4] print("The largest multiple is " + str(largest_multiple)) print("The corresponding substring is " + largest_multiple_string)

Anonymous op

Voeg antwoorden of opmerkingen toe

Meld u aan of registreer u om hier een opmerking over te maken.