Prepin
Log in

How would you create and execute a password checker based on specific password requirements?

Approach / Explanation

This question can be divided into several essential components: You need to create a password checker: Essentially, you are required to develop a plan or framework for how you would configure a program or algorithm to evaluate passwords based on specific criteria. You must execute this design: Once you have outlined your design, you should convert this into code using a programming language of your choice. The password checker should adhere to certain password requirements : This means that there must be defined criteria or regulations that the password must meet, such as a minimum length, the presence of various character types (uppercase, lowercase, digits, special symbols, etc.), and any other limitations. Identifying the password requirements. The processes necessary to verify the provided password against these requirements. Discussing any efficiency considerations, if relevant. Providing a sample implementation of the password checker.

Suggested Answer

Considering the password criteria, which include a minimum length of 8 characters, at least one uppercase letter, one lowercase letter, and one special character, I would create a password validator as follows: Initially, check if the password satisfies the minimum length condition. Next, examine each character in the password to confirm it fulfills the various character criteria. Now, here’s how the implementation would look: def password_checker ( password ) : if len ( password ) < 8 : return "Password is too short" if not any ( c . isupper ( ) for c in password ) : return "Password needs at least one uppercase letter" if not any ( c . islower ( ) for c in password ) : return "Password needs at least one lowercase letter" if not any ( c in "!@#$%^&*()" for c in password ) : return "Password needs at least one special character" return "Password is valid" It's important to note that this method checks each requirement in distinct steps, resulting in straightforward and clear code, although it may involve multiple iterations over the password.

Alternative Answer

An improved version of this function can validate all the criteria in a single iteration: def password_checker ( password ) : min_length = 8 has_upper = has_lower = has_special = False if len ( password ) < min_length : return "Password is too short" for c in password : if c . isupper ( ) : has_upper = True elif c . islower ( ) : has_lower = True elif c in "!@#$%^&*()" : has_special = True if not has_upper : return "Password needs at least one uppercase letter" if not has_lower : return "Password needs at least one lowercase letter" if not has_special : return "Password needs at least one special character" return "Password is valid" This implementation checks all the necessary conditions in a single loop through the password. It uses boolean flags for each requirement, setting them to true upon encountering the respective condition. This approach not only fulfills the criteria but also enhances efficiency.

Question Details

Difficulty & Category

Medium
algorithms

Companies

Peloton

Product

For CandidatesFor RecruitersCompaniesBrowse JobsInterview QuestionsDeep ProfileSkill AssessmentOpportunity Matching
Prepin.ai

© 2026 Prepin LLC · Philadelphia, PA · All rights reserved.