• + 0 comments

    function passwordCracker(passwords, loginAttempt) {

    const memo = {};
    
    function helper(s) {
        if (s.length === 0) return [];
        if (memo[s] !== undefined) return memo[s]; 
    
        for (let pwd of passwords) {
            if (s.startsWith(pwd)) {
                const rest = helper(s.slice(pwd.length));
                if (rest !== null) {
                    memo[s] = [pwd, ...rest];
                    return memo[s];
                }
            }
        }
    
        memo[s] = null; 
        return null;
    }
    
    const result = helper(loginAttempt);
    return result ? result.join(" ") : "WRONG PASSWORD";
    

    }