TopcoderARCHIVE
Archive/Problems/DistinctStrings
SRM · Problem 17081

DistinctStrings

Problem statement, definition, constraints, and public examples.

Problem Statement

Help Donna pick a password!

Her password should have exactly L characters. The letters the password may contain are given in the String letters.

Generate N mutually distinct possible passwords for Donna, so that she can pick one that appeals to her. Return the generated passwords in a String[]

Definition

Class:
DistinctStrings
Method:
generate
Parameters:
int, String, int
Returns:
String[]
Method signature:
String[] generate(int L, String letters, int N)
(be sure your method is public)

Notes

  • Any valid answer will be accepted.
  • For the given constraints a valid answer always exists.

Constraints

  • L will be between 3 and 10, inclusive.
  • letters will have between 10 and 62 characters, inclusive.
  • The characters in letters will be a subset of [a-zA-Z0-9] (i.e., letters and digits).
  • All characters in letters will be mutually distinct.
  • N will be between 1 and 200, inclusive.

Examples

  1. 5
    "qwertyuiopasdfghjklzxcvbnm"
    10
    Returns: {"hello", "abcde", "wwwww", "coins", "coder", "digit", "clash", "qwert", "puppy", "kitty" }
    We want 10 different password suggestions. Each must be a 5-character string of lowercase letters.
  2. 3
    "ABCDE02468"
    17
    Returns: {"ABC", "D2E", "DDD", "AAA", "EEE", "024", "042", "204", "240", "402", "420", "4AB", "4EE", "E4E", "ED4", "868", "844" }
    Here we want 17 distinct password suggestions. Each must have three characters, and each of those must be one of the first five uppercase letters or an even digit.
  3. 8
    "cdeopPrRtT"
    4
    Returns: {"topcoder", "Topcoder", "docopTer", "receptor" }
    Case matters. The first two password suggestions are distinct because one starts with a lowercase t and the other with an uppercase T.
← All problems