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.
constSPECIAL_CHARS:&'staticstr="!@#$%^&*()-+";fnminimumNumber(n:i32,password:&str)->i32{// Return the minimum number of characters to make the password strongletmissing_char=ifn<6{6-n}else{0};letmutcriteria=[0;4];forcinpassword.chars(){ifSPECIAL_CHARS.contains(c){criteria[0]+=1;}elseifc.is_digit(10){criteria[1]+=1;}elseifc.is_lowercase(){criteria[2]+=1;}elseifc.is_uppercase(){criteria[3]+=1;}}letmissing_criteria=criteria.iter().map(|&x|ifx>0{0}else{1}).sum::<i32>();ifmissing_char>=missing_criteria{missing_char}else{missing_criteria}}
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 →
My rust solution: