Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Strong Password in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To Algorithm
The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results.
Advantages of Algorithms:
- It is easy to understand.
- Algorithm is a step-wise representation of a solution to a given problem.
- In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.
Link for the Problem – Strong Password– Hacker Rank Solution
Strong Password – Hacker Rank Solution
Problem:
Louise joined a social networking site to stay in touch with her friends. The signup page required her to input a name and a password. However, the password must be strong. The website considers a password to be strong if it satisfies the following criteria:
- Its length is at least .
- It contains at least one digit.
- It contains at least one lowercase English character.
- It contains at least one uppercase English character.
- It contains at least one special character. The special characters are:
!@#$%^&*()-+
She typed a random string of length in the password field but wasn’t sure if it was strong. Given the string she typed, can you find the minimum number of characters she must add to make her password strong?
Note: Here’s the set of types of characters in a form you can paste in your solution:
numbers = "0123456789" lower_case = "abcdefghijklmnopqrstuvwxyz" upper_case = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" special_characters = "!@#$%^&*()-+"
Example
This password is 5 characters long and is missing an uppercase and a special character. The minimum number of characters to add is .
This password is 5 characters long and has at least one of each character type. The minimum number of characters to add is .
Function Description
Complete the minimumNumber function in the editor below.
minimumNumber has the following parameters:
- int n: the length of the password
- string password: the password to test
Returns
- int: the minimum number of characters to add
Input Format
The first line contains an integer , the length of the password.
The second line contains the password string. Each character is either a lowercase/uppercase English alphabet, a digit, or a special character.
Constraints
- All characters in are in [a-z], [A-Z], [0-9], or [!@#$%^&*()-+ ].
Sample Input 0
3 Ab1
Sample Output 0
3
Explanation 0
She can make the password strong by adding characters, for example, $hk
, turning the password into Ab1$hk
which is strong.
characters aren’t enough since the length must be at least .
Sample Input 1
11 #HackerRank
Sample Output 1
1
Explanation 1
The password isn’t strong, but she can make it strong by adding a single digit.
Strong Password – Hacker Rank Solution
import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution { static int minimumNumber(int n, String password) { boolean lowercase = false; boolean uppercase = false; boolean number = false; boolean special = false; char[] schars = "!@#$%^&*()-+".toCharArray(); Set<Character> cs = new HashSet<>(); for (char c : schars) { cs.add(c); } for (int i = 0; i < n; i++) { char c = password.charAt(i); if (c >= '0' && c <= '9') number = true; if (c >= 'a' && c <= 'z') lowercase = true; if (c >= 'A' && c <= 'Z') uppercase = true; if (cs.contains(c)) special = true; } int need = 0; need += lowercase ? 0 : 1; need += uppercase ? 0 : 1; need += number ? 0 : 1; need += special ? 0 : 1; return n + need < 6 ? 6 - n : need; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); String password = in.next(); int answer = minimumNumber(n, password); System.out.println(answer); in.close(); } }
Grеetіngs from Floridа! I’m bored to tears at work so I decided to check out your blog on my iphone dսring lunch
break. I really like the information you provіde here and can’t wait to
take a look when I get home. I’m surprised at how quick your blog loaded on my mobile ..
I’m not even using WIFI, just 3G .. Anyhⲟw, vеry good
blog!
generic cialis canada buy generic tadalafil 40mg buy generic ed pills for sale
buy cefadroxil 500mg sale propecia cost propecia 1mg cost
buy fluconazole pills purchase diflucan for sale cipro tablet
buy estradiol generic estradiol 1mg generic minipress 2mg
brand metronidazole 200mg order bactrim 480mg generic where can i buy keflex
mebendazole for sale online vermox 100mg canada order tadalafil 10mg online cheap
buy clindamycin cheap order cleocin 150mg online cheap sildenafil 50mg cheap
buy nolvadex 20mg online cheap buy cefuroxime buy ceftin online
buy cheap indocin order indomethacin 50mg pill order suprax 200mg pill
bimatoprost buy online purchase bimatoprost generic buy generic desyrel for sale
trimox 500mg without prescription buy arimidex 1mg pill buy clarithromycin pill
buy clonidine 0.1 mg online cheap generic meclizine 25 mg tiotropium bromide cheap
suhagra 100mg without prescription sildenafil 100mg drug sildenafil online
order generic minocycline actos medication actos 30mg generic
accutane uk isotretinoin 10mg brand buy generic zithromax 500mg
order arava sale order leflunomide 10mg online order azulfidine pills
azithromycin 250mg ca azithromycin 500mg drug order gabapentin pill
buy cialis online buy cialis pills tadalafil oral
lasix 40mg oral ventolin inhalator online order albuterol pills
order levitra 10mg online buy zanaflex for sale hydroxychloroquine 200mg over the counter
order olmesartan 20mg generic benicar us buy depakote pills for sale
purchase coreg pill oral cenforce 50mg chloroquine online
acetazolamide 250 mg oral purchase isosorbide online cheap azathioprine 25mg
order lanoxin online cheap lanoxin 250mg tablet molnunat uk
order generic naprosyn 250mg prevacid 30mg price lansoprazole 30mg for sale
baricitinib brand order lipitor 80mg generic lipitor 80mg without prescription
order proventil 100 mcg without prescription buy albuterol without prescription phenazopyridine over the counter
buy singulair 10mg sale cost singulair 5mg buy avlosulfon no prescription
order norvasc sale purchase prinivil generic buy prilosec online
buy adalat 10mg online order aceon 8mg for sale buy allegra 120mg online