Password Cracker

Password Cracker - A HackerRank challenge solution

Problem

There are N users registered on a website CuteKittens.com. Each of them has a unique password represented by pass[1], pass[2], ..., pass[N]. As this 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.

Yu, being an awesome hacker finds a loophole in the password verification system. A string which is a concatenation of one or more passwords, in any order, is also accepted by the password verification system. Any password can appear 0 or more times in that string. Given access to each of the n passwords, and also have a string loginAttempt,determinewhetherthisstringbeacceptedbythepasswordverificationsystemofthewebsite loginAttempt$ string can be created by concatenating password strings, it is accepted.

For example, if there are 3 users with passwords = [abra, ka, dabra], then some of the valid combinations are abra (password[1]), kaabra (password[2] + password[1]), kadabraka (password[2] + password[3] + password[2]), kadabraabra (password[2] + password[3] + password[1]) and so on. Supplying abra ka dabra, concatenated, passes authentication.

Function Description

Complete the passwordCracker function in the editor below. It should return the passwords as a single string in the order required for the password to be accepted, each separated by a space. If it is not possible to form the string, return the string WRONG PASSWORD.

passwordCracker has the following parameters:

  • passwords: a list of password strings
  • loginAttempt: the string to attempt to create

Read more on the challenge page…


Problem Analysis And Solution


My Solution

I’m providing the solution for Python and JS, please leave on the comments if you found a better way.

Si te gusta el contenido, por favor apoya mi trabajo!

Juan Cruz Martinez - Author @ Live Code Stream

Juan Cruz Martinez

¡Hola!

Soy Juan Cruz Martinez, el fundador de LiveCodeStream.dev. Me encanta programar y creo en el poder de la programación no solo para construir un mundo mejor, sino para hacer que TU vida sea mejor.

Fundé LiveCodeStream.dev porque quería ayudarte a aprender a programar, construir una mejor carrera y, en última instancia, crear una vida mejor. Eso me sucedió hace más de una década cuando comencé a programar, y le sucede a decenas de miles de personas a diario. Quiero que TÚ te unas a esa revolución.

No importa cómo lo llames, escribir código, programación, desarrollo de software o cualquier otra cosa, las habilidades involucradas están en una demanda cada vez mayor. Y ya sea que quieras incursionar en el desarrollo de sitios web, diseño de juegos, desarrollo de blockchain o cualquier otra cosa, quiero ayudarte.