VOOZH about

URL: https://www.geeksforgeeks.org/dsa/generate-passwords-of-given-length/

⇱ Generate Passwords of given length - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Generate Passwords of given length

Last Updated : 15 Jul, 2025

Given an integer N, the task is to generate random passwords of length N of easy, medium and strong level each.

Easy level Password: Consists of only numbers or letters. Medium level Password: Consists of Letters as well as numbers. Strong level Password - Consists of Letters, numbers, and/or special characters.

Examples:

Input: N = 5 Output: Easy level password (only numbers): 98990 Easy password (only letters): tpFEQ Medium level password: b3bC8 Strong level password: 7`74n Input: N = 7 Output: Easy level password (only numbers): 7508730 Easy level password (only letters): mDzKCjN Medium level password: 4Z05s66 Strong level password: 2384Qu9

Approach: Follow the steps below to solve the problem:

  • For each password level, iterate through the given length.
  • To generate each password, randomly assign characters and numbers using Random Number Generation based on the password level.

Below is the implementation of the above approach: 


Output
Easy level password (only numbers): 11973
Easy level password (only letters): AZYnW
Medium level password: oo7c6
Strong level password: ,5Cc4

Time Complexity: O(N) 

Auxiliary Space: O(N)

Comment
Article Tags:
Article Tags: