Connection Status:
Competition Arena > GoodLetters
SRM 835 · 2022-08-15 · by misof · Simple Search, Iteration, String Manipulation
Class Name: GoodLetters
Return Type: String
Method Name: construct
Arg Types: (string, int, int)
Problem Statement

Problem Statement

All letters in this problem are uppercase English letters: 'A' to 'Z'. In other words, the 26 letters one can find on a standard US keyboard.


You are given the String good. The letters that appear (one or more times) in good are good. The letters that don't appear in good are bad.

You are also given the ints N and G.

We are looking for a string with the following properties:

  • It consists of exactly N letters.
  • All those letters are mutually distinct.
  • Exactly G letters in this string are good.

If such strings exist, construct and return any one such string. Otherwise, return an empty string.

Constraints

  • good will have between 0 and 50 characters, inclusive.
  • Each character in good will be from 'A'-'Z'.
  • N will be between 1 and 26, inclusive.
  • G will be between 0 and N, inclusive.
Examples
0)
"AEIOU"
10
3
Returns: "BLUEPRINTS"

Vowels are good, consonants are bad. We want a 10-character string with 3 distinct vowels and 10-3 = 7 distinct consonants.

1)
"AAEEIOUIOUIOU"
10
3
Returns: "BLUEPRINTS"

This is essentially the same test case as in the previous example. Multiple occurrences of the same letter in good have no effect. The good letters are still exactly 'A', 'E', 'I', 'O', and 'U'.

2)
""
7
1
Returns: ""

There are no good letters at all, and therefore there is no string with 7 letters out of which one is good.

3)
"EEEEE"
5
2
Returns: ""

Remember that we cannot repeat letters. The goal here is to create a string that has two distinct good letters, but the only good letter is 'E'.

4)
"QWERTYUIOPASDFGHJKLZXC"
10
5
Returns: ""
5)
""
3
0
Returns: "ABC"

Here we want a string of three distinct bad letters. Any such string, for example "CAT" or "DOG", will be accepted.

Submissions are judged against all 95 archived test cases, of which 6 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class GoodLetters with a public method string construct(string good, int N, int G) · 95 test cases · 2 s / 256 MB per case

Submitting as anonymous