Join Regular Classroom : Visit ClassroomTech

Password Generator – Infytq 2019 Solve

Problem: Take input from user in the given format (consist of name and code), find max digit from Code which is less or equal to the length of String and put that place Char in final String if there is no any digit found which not satisfy the condition that simply put ‘X’.

Sample Input:

Abhishek:34848,Mayur:4739,Friends:2949,Yeah:9889

Sample Output:

kueX

Solution: We strongly recommend you to try the problem first before moving to the solution.

# Solution of Password Generator problem in Python 
# www.codewindow.in 

input_str=input()
list_input=[]
finalString=''

list_input=input_str.split(',')

for i in list_input:
    temp=i.split(':')
    name=temp[0]
    number=temp[1]
    length=len(name)
    mx=0
    for digit in number:
        if(int(digit)<=length):
            if(mx<int(digit)):
                mx=int(digit)
    if mx==0:
        finalString+='X'
    else:
        finalString+=name[mx-1]

print(finalString)

Input:

Abhishek:34848,Mayur:4739,Friends:2949,Yeah:9889

Output:

kueX

Follow Us

You Missed