Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Random Password Generator

HardPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Random Password Generator. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

WorldQuant needs short one-time credentials for an internal research workflow. Implement generate_passwords to return a requested number of unique passwords while preserving uniform randomness across every valid password sequence.

Formal Specification

The function receives count and an optional integer seed. Return a list of exactly count strings. Every string must have length 4, use only characters from A-F, a-f, and 1-6, and contain at least one uppercase letter, one lowercase letter, and one digit. No two returned strings may be equal.

When seed is None, use a system-backed random generator. When a seed is supplied, use it only to make tests reproducible. Every valid password must have equal probability of appearing at each position in the generated sequence, subject to sampling without replacement.

Example 1: count = 2 may return ['aB3F', '6cDA']. Both strings satisfy all character and uniqueness rules.

Example 2: count = 1 may return ['A1bc']. It contains one uppercase letter, one lowercase letter, and one digit.

Constraints

  • 0 <= count <= 46656
  • seed is None or an integer
  • Only A-F, a-f, and 1-6 may appear
  • Every password must contain at least one uppercase letter, one lowercase letter, and one digit
  • The valid password universe contains exactly 46656 strings

Function Signature

def generate_passwords(count, seed=None):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output