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.
Hi.
So first we check the number of capital letters, small letters, digits and special characters.
Then after that, we check if any of the above(capital letters, small letters, digits and special characters) is 0, we increment count so that we include one of them because the question clearly states that it should have atleast one of capital letters, small letters, digits and special characters.
Coming to the last if statement,
We check the sum of (capital letters, small letters, digits and special characters) with count( to make sure it has one of capital letters, small letters, digits and special characters in case any of it is 0), if this is less than 6, we add the minimum number to it to make it 6.
Say eg: input string is aA#
so l=1, u=1, s=1
next it has no digits so it makes count =1( to make up for the missing digit)
so now l+u+s+n(which is 0) + count=4. even though this satisfies all the type of characters to be used, it is still less than 6..so last if statement takes care of this condition..it adds (6-4) to count
if( (u+l+s+n+count) < 6 ):
count=count+(6-(u+l+s+n+count))
Hope it clarifies your doubt.
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 →
Hi. So first we check the number of capital letters, small letters, digits and special characters. Then after that, we check if any of the above(capital letters, small letters, digits and special characters) is 0, we increment count so that we include one of them because the question clearly states that it should have atleast one of capital letters, small letters, digits and special characters. Coming to the last if statement, We check the sum of (capital letters, small letters, digits and special characters) with count( to make sure it has one of capital letters, small letters, digits and special characters in case any of it is 0), if this is less than 6, we add the minimum number to it to make it 6. Say eg: input string is aA# so l=1, u=1, s=1 next it has no digits so it makes count =1( to make up for the missing digit) so now l+u+s+n(which is 0) + count=4. even though this satisfies all the type of characters to be used, it is still less than 6..so last if statement takes care of this condition..it adds (6-4) to count if( (u+l+s+n+count) < 6 ): count=count+(6-(u+l+s+n+count))
Hope it clarifies your doubt.