#K54782. Validate Quiz Questions

    ID: 29830 Type: Default 1000ms 256MiB

Validate Quiz Questions

Validate Quiz Questions

You are given a dictionary of quiz questions in JSON format. Each key represents a unique question ID, and each corresponding value is an object containing the question text and an array of answer choices. A question is considered valid if and only if it has exactly 4 answer choices and each choice is a string whose length is between 1 and 50 characters (inclusive).

Your task is to filter out any invalid questions and output a JSON object containing only the valid questions. All input and output is provided via standard input (stdin) and standard output (stdout) respectively.

For example, given the following input:

{
  "Q1": {"question": "What is the capital of France?", "choices": ["Paris", "Lyon", "Marseille", "Nice"]},
  "Q2": {"question": "What is 2 + 2?", "choices": ["4", "Four"]}
}

The output should be:

{
  "Q1": {"question": "What is the capital of France?", "choices": ["Paris", "Lyon", "Marseille", "Nice"]}
}

inputFormat

The input is provided via stdin as a single JSON object. This object represents a dictionary where each key is a question ID and each corresponding value is an object with two properties:

  • question: A string representing the text of the question.
  • choices: An array of strings representing the answer choices.

There are no extra spaces or lines before or after the JSON string.

outputFormat

Output the filtered JSON object to stdout. The output should be a JSON object containing only the valid questions. A question is valid if:

  • It has exactly 4 choices.
  • Each choice is a string with length between 1 and 50 (inclusive).

The order of the keys must remain the same as in the input.

## sample
{"Q1": {"question": "What is the capital of France?", "choices": ["Paris", "Lyon", "Marseille", "Nice"]}, "Q2": {"question": "What is 2 + 2?", "choices": ["4", "Four"]}}
{"Q1": {"question": "What is the capital of France?", "choices": ["Paris", "Lyon", "Marseille", "Nice"]}}