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:
`[email protected]#$%^&*()-+`

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 = "[email protected]#$%^&*()-+"

**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 [[email protected]#$%^&*()-+ ].

**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 = "[email protected]#$%^&*()-+".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(); } }