# HackerRank Password Cracker problem solution

In this HackerRank Password Cracker problem solution, There are n users registered on the website CuteKittens.com. Each of them has a unique password represented by pass[1], pass[2], ..., pass[N]. As this is a very lovely site, many people want to access those awesomely cute pics of the kittens. But the adamant admin does not want the site to be available to the general public, so only those people who have passwords can access it.

## Problem solution in Python.

```import sys
sys.setrecursionlimit(5000)
testcases = int(input())
memo = {}

global memo
if strLoc not in memo and strLoc != len(attempt):
fail_path = True
if len(password) <= (len(attempt) - strLoc):
if len("".join(output)) == len(attempt):
fail_path = False
break
if fail_path:
memo[strLoc] = True

if strLoc in memo:
output = output[:-1]

return output

for i in range(testcases):
memo = {}
input()
attempt = input()
output = solve(attempt, passwords, [], 0)
if len("".join(output)) != len(attempt):
else:
print(" ".join(output))
```

## Problem solution in Java.

```import java.io.*;
import java.util.*;

public class Solution {

private static boolean calc(String[] pass, String loginAttempt) {
return false;
}
return true;
}
for(String p : pass) {
return true;
}
}
return false;
}

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 0; i < t; i++) {
int n = in.nextInt();
String[] pass = new String[n];
for(int j = 0; j < n; j++) {
pass[j] = in.next();
}
if(result) {
}
System.out.println();
} else {
}
}
}
}```

## Problem solution in C++.

```#include <iostream>
#include<string>
#include <stdlib.h>
#include <map>

using namespace std;
int sizes=0;
int check=0;
map<int , int> maper;
void preform(string arrays[],int n,string attemt,int start,string outer[]){
if(maper[start]==2){
return;
}
if(check==1){
return;

}
if(start==attemt.length()){
check=1;
return;
}
for(int i = 0;i<n;i++){
string x = arrays[i];
if(x.length()>attemt.length()-start){
continue;
}
string newstr = attemt.substr(start,x.length());
int newsizes = sizes;
if(x.compare(newstr)==0){
outer[sizes]=newstr;
sizes++;
preform(arrays,n,attemt,start+x.length(),outer);
}
if(check==1){
return;
}
sizes=newsizes;

}
if(check==0){
maper[start]=2;
}

}

int main()
{
int t;
cin>>t;
string out[t];
for (int i = 0;i<t;i++){
string outer[2001];
int n;
cin>>n;
string arrays[n];
for(int j=0;j<n;j++){
cin>>arrays[j];
}
string attempt;
cin>>attempt;
preform(arrays,n,attempt,0,outer);
if(check==1){
for(int j = 0;j<sizes;j++){
out[i]+=outer[j]+" ";
}
sizes=0;
check=0;
maper.clear();
}else{
sizes=0;
check=0;
maper.clear();
}
}
for(int i = 0;i<t;i++){
cout<<out[i]<<'\n';
}
return 0;
}```

## Problem solution in C.

```#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void solve(int idx);
char a[10][11],str[2001];
int dp[2000],N,len;

int main(){
int T,i;
scanf("%d",&T);
while(T--){
memset(dp,-1,sizeof(dp));
scanf("%d",&N);
for(i=0;i<N;i++)
scanf("%s",&a[i][0]);
scanf("%s",str);
len=strlen(str);
solve(0);
if(dp[0]==-2)
else{
i=0;
while(i<len){
printf("%s ",&a[dp[i]][0]);
i+=strlen(&a[dp[i]][0]);
}
printf("\n");
}
}
return 0;
}
void solve(int idx){
int i;
if(idx>=len || dp[idx]!=-1)
return;
for(i=0;i<N;i++)
if(!strncmp(&str[idx],&a[i][0],strlen(&a[i][0])))
if(!str[idx+strlen(&a[i][0])]){
dp[idx]=i;
break;
}
else{
solve(idx+strlen(&a[i][0]));
if(dp[idx+strlen(&a[i][0])]>=0){
dp[idx]=i;
break;
}
}
if(dp[idx]==-1)
dp[idx]=-2;
return;
}
```