Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

public class PasswordCracker {

static Map<Integer, Boolean> dp = new HashMap<>();

private static boolean solve(String[] passwords, String loginAttempt, int


index, List<String> usedSoFar) {

if (loginAttempt.length() == index) {
return true;
}

if (dp.containsKey(index)) {
return false;
}

for (String password : passwords) {


if (loginAttempt.startsWith(password, index)) {
usedSoFar.add(password);

if (solve(passwords, loginAttempt, index +


password.length(), usedSoFar)) {
return true;
}

usedSoFar.remove(usedSoFar.size() - 1);
}
}

dp.put(index, false);

return false;
}

/*

static long getWays(long n, long[] c) {

int[][] arr = new int[c.length+1][(int)n+1];

//System.out.print(c.length+" "+n);

for(int i=0;i<c.length+1;i++)
{
for(int j=0;j<n+1;j++)
{
if(j==0)
{
arr[i][j] = 1;

}
// System.out.println(i+" "+j);
if(i>0 && j>0)
{ if( j < (int) c[i-1])
{
arr[i][j] = arr[i-1][j];
}
else
{
arr[i][j] = arr[i-1][j]+arr[i][j-(int)c[i-1]];
}
}

for(int i=0;i<c.length+1;i++)
{

for(int j=0;j<n+1;j++)
{
System.out.print(arr[i][j]+" ");
}
System.out.println();

System.out.println(arr[c.length][(int)n]);

return (long)arr[c.length][(int)n];
}

*/

You might also like