Generate a string from an array of alphanumeric strings based on given conditions | Function to generate required string ; To store the result ; Split name and number ; Stores the maximum number less than or equal to the length of name ; Check for number by parsing it to integer if it is greater than max number so far ; Check if no such number is found then we append X to the result . ; Otherwise ; Append max index of the name ; Return the final string ; Driver Code ; Function call
def generatePassword ( s , T ) : NEW_LINE INDENT result = [ ] NEW_LINE for currentString in s : NEW_LINE INDENT person = currentString . split ( " : " ) NEW_LINE name = person [ 0 ] NEW_LINE number = person [ 1 ] NEW_LINE n = len ( name ) NEW_LINE max = 0 NEW_LINE for i in range ( len ( number ) ) : NEW_LINE INDENT temp = int ( number [ i ] ) NEW_LINE if ( temp > max and temp <= n ) : NEW_LINE INDENT max = temp NEW_LINE DEDENT DEDENT if max == 0 : NEW_LINE INDENT result . append ( T ) NEW_LINE DEDENT else : NEW_LINE INDENT result . append ( name [ max - 1 ] ) NEW_LINE DEDENT DEDENT return result NEW_LINE DEDENT arr = [ " Geeks : 89167" , " gfg : 68795" ] NEW_LINE T = ' X ' NEW_LINE print ( * generatePassword ( arr , T ) , sep = " " ) NEW_LINE