TopcoderArchiveVisit Topcoder
SRM7 Nov 2002
SRM 119

NumberGuess

Problem statement, definition, constraints, and public examples.

Problem Statement

You are watching two children playing a number game. Aaron thinks of a number between 1 and 8 inclusive. Kate needs to guess this number by asking yes or no questions. You know that Aaron may give a wrong answer, but not more than one wrong answer per round.

Your task is, given Kate's questions and Aaron's answers over the course of a single round, return the number Aaron thought of, or one of the two Strings: "CONTRADICTION" or "NOT ENOUGH INFO".

In more detail:

  • the answers are in the same order as the questions
  • Kate's questions are presented as a list of numbers separated by spaces. For example, if Kate asks: "Is this number more than 5?", this question is translated to the form: "Is this number from the set {6, 7, 8}?" and the input String would list the set in ascending order: "6 7 8"
  • Aaron's answer is always either "YES" or "NO"
  • return "CONTRADICTION" when the answers contradict the fact that Aaron lies not more than once (see examples)
  • return "NOT ENOUGH INFO" when Aaron's number is not uniquely determined, and there is no contradiction
  • in all other cases return the number Aaron thought of

Definition

Class:
NumberGuess
Method:
answer
Parameters:
String[], String[]
Returns:
String
Method signature:
String answer(String[] questions, String[] answers)
(be sure your method is public)

Constraints

  • questions has between 1 and 10 elements inclusive
  • answers must contain the same number of elements as questions
  • each element of questions has between 1 and 15 characters inclusive
  • each element of questions consists of digits between 1 and 8 inclusive and spaces
  • each element of questions starts and ends with a digit
  • each element of questions doesn't have two spaces or two digits in a row
  • digits in an element of questions are distinct and in ascending order
  • each element of answers is either "YES" or "NO"

Examples

  1. {"1 2 3"}
    {"YES"}
    Returns: "NOT ENOUGH INFO"
  2. {"1 2 3","1 2 3","1 2 3","1 2 3"}
    {"YES","NO","YES","NO"}
    Returns: "CONTRADICTION"
  3. {"1","1"}
    {"YES","YES"}
    Returns: "1"
  4. {"1 2 3 4","1 2","1","1 3"}
    {"YES","YES","YES","YES"}
    Returns: "1"
  5. {"1 2 3 4","1 2","1"}
    {"YES","YES","YES"}
    Returns: "NOT ENOUGH INFO"
    as Aaron could have thought of 1 and given all true answers or he could have thought of 2, and lied on the last answer
Back to all problems