forked from rajatgoyal715/Hackerrank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongPassword.java
More file actions
47 lines (41 loc) · 1.2 KB
/
StrongPassword.java
File metadata and controls
47 lines (41 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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 pwd) {
if(n<=3) return 6-n;
boolean num = false, lower = false, upper = false, special = false;
for(char c : pwd.toCharArray()){
if(isNum(c)) num = true;
else if(isLower(c)) lower = true;
else if(isUpper(c)) upper = true;
else special = true;
}
boolean length = (n>=6);
int count = 0;
if(!num) count++;
if(!lower) count++;
if(!upper) count++;
if(!special) count++;
return (count+n < 6) ? 6-n : count;
}
static boolean isNum(char c){
return (c>='0' && c<='9');
}
static boolean isLower(char c){
return (c>='a' && c<='z');
}
static boolean isUpper(char c){
return (c>='A' && c<='Z');
}
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();
}
}