We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defminimumNumber(n,password):# Define character setsnumbers="0123456789"lower_case="abcdefghijklmnopqrstuvwxyz"upper_case="ABCDEFGHIJKLMNOPQRSTUVWXYZ"special_characters="!@#$%^&*()-+"# Flags for each type of characterhas_digit=has_lower=has_upper=has_special=False# Check the presence of each type of character in the passwordforcharinpassword:ifcharinnumbers:has_digit=Trueelifcharinlower_case:has_lower=Trueelifcharinupper_case:has_upper=Trueelifcharinspecial_characters:has_special=True# Count the number of missing character typesmissing_types=0ifnothas_digit:missing_types+=1ifnothas_lower:missing_types+=1ifnothas_upper:missing_types+=1ifnothas_special:missing_types+=1# Calculate the minimum number of characters to add# It should be the maximum of missing types and (6 - n)returnmax(missing_types,6-n)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Strong Password
You are viewing a single comment's thread. Return to all comments →