Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions C++/420-strong-password-checker.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 420-strong-password-checker.cpp
// Problem: https://leetcode.com/problems/strong-password-checker/
//

class Solution {
public:
int strongPasswordChecker(string password) {
int x = password.size();
bool lower = false;
bool upper = false;
bool digit = false;

for(char i:password){
if(islower(i)){
lower = true;
}
if (isupper(i)){
upper = true;
}
if(isdigit(i)){
digit = true;
}
}

int miss = !lower + !upper + !digit;
int change = 0;
int one = 0;
int two = 0;

for (int i =2;i<x;i++){
if (password[i]==password[i-1] && password[i-1]==password[i-2]){
int j = i;
while (j < x && password[j]== password[i-2]){
j++;
}
int len = j -(i-2);
change +=len/3;
if(len % 3 == 0){
one++;
}
else if(len %3 == 1){
two++;
}
i = j - 1;
}
}

if (x<6){ //CASE 1: TOO SHORT
return max(miss,6-x);
}

else if(x <=20){ //CASE 2: IDEAL RANGE
return max(miss,change);
}

else{ //REST, CASE 3: TOO LONG
int del = x -20;
change = change - min(del,one);
change = change - min(max(0,del-one), two *2)/2;
change = change - max(0,del-one-two*2)/3;
return del + max(miss, change);
}
}
};
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ DISCLAIMER: This above mentioned resources have affiliate links, which means if

| Name | Country | Programming Language | Where to find you<br><sup>(add all links to your profiles eg on Hackerrank, Codechef, LeetCode...)</sup> |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | -------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Genji J](https://github.com/anya-minamoto) <br> <img src="https://github.com/anya-minamoto.png" width="100" height="100"> | Indonesia | C++ | [GitHub](https://github.com/anya-minamoto) <br> [LeetCode](https://leetcode.com/u/anya-minamoto/) |
| [Gourav R](https://github.com/GouravRusiya30/) <br> <img src="https://github.com/GouravRusiya30.png" width="100" height="100"> | India | Java | [codedecks](https://www.youtube.com/c/codedecks/) <br> [Hackerrank](https://www.hackerrank.com/gouravrusiya786) <br> [LeetCode](https://leetcode.com/rusiya/) |
| [Dima Vishnevetsky](https://github.com/dimshik100) <br> <img src="https://github.com/dimshik100.png" width="100" height="100"> | Israel | JavaScript | [Twitter](https://twitter.com/dimshik100) <br> [Facebook](https://www.facebook.com/dimshik) |
| [Anuj Sharma](https://github.com/Optider/) <br> <img src="https://github.com/Optider.png" width="100" height="100"> | India | Python | [Github](https://github.com/Optider) |
Expand Down