## Questions d'entretien

Entretien pour 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.

Répondre

## Réponses aux questions d'entretien

4 réponse(s)

0

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

guych le

0

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

guych2 le

0

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 le

0

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 le

## Ajouter des réponses ou des commentaires

Pour commenter ceci, connectez-vous ou inscrivez-vous.