Program to check the validity of a Password
Ninjas are trying to hack a system of a terrorist organization so that they can know where they will be going to attack next. But to hack the system and to get access to data they need a password that must satisfy certain conditions as described below:
1) Length of the password must be between 8 to 15 characters.
2) At least one digit (0-9), one lowercase letter (a-z), one uppercase letter (A-Z) and one special character (%, ^, &, #, *, %, etc) must be present.
3) Password must not contain any space.
You are given a string ‘STR’, help ninjas to find whether it's a valid password or not.
For example :
Given ‘STR’ = “Codingninja#1” As it satisfies all the above conditions so it is a valid password and therefore you have to return true.
Input Format
The first line of input contains an integer 'T' representing the number of test cases.
The description of the next ‘T’ lines is as follows-.
The first and the only line of each test case contains a single string 'STR' representing the password.
Output Format:
For each test case, return “Valid” if the given string ‘STR’ satisfies all the above conditions and “Not Valid” if it's not.
The output of each test case will be printed in a separate line.
Constraints:
1 <= T <= 5
1 <= |STR| <= 5*10^3
Time Limit: 1 second
CodingNinjas
author
2y
1.) Maintained 4 flags as "false" for checking the capital letter, small letter, special character and number.
2.) Iterated the string and checking every character in it for the above 4 flags.
3.) If ei...read more
CodingNinjas
author
2y
Conditional Implementation
The idea here is we will check all conditions one by one, if any condition fails at any instance we will directly return false and output Not valid password else we will outp...read more
CodingNinjas
author
2y
String Based Search Approach
In this approach, we will use the find function to find a particular character if the character is present then it will return its position else it will return the end of t...read more
Add answer anonymously...
Top UnitedHealth Software Developer Intern interview questions & answers
Popular interview questions of Software Developer Intern
>
UnitedHealth Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app