TopcoderArchiveVisit Topcoder
SRM29 Jan 2015
SRM 653

CountryGroupHard

Problem statement, definition, constraints, and public examples.

Problem Statement

Some people are sitting in a row. Each person came here from some country. People from the same country are all sitting together.

A reporter has already approached some of the people and asked each of them the same question: "How many people from your country (including you) are here?" All the people who were asked the question gave her correct answers.

You are given a int[] a. The elements of a correspond to the people in the row, in order. For each i, element i of a is either 0 if the corresponding person was not asked the question, or a positive integer: the answer given by that person.

The reporter just realized that she might be able to reconstruct all the missing answers from the answers she already knows. Return "Sufficient" if she can do that, or "Insufficient" if she cannot.

Definition

Class:
CountryGroupHard
Method:
solve
Parameters:
int[]
Returns:
String
Method signature:
String solve(int[] a)
(be sure your method is public)

Constraints

  • The number of elements in a will be between 1 and 100, inclusive.
  • All numbers of a will be between 0 and 100, inclusive.
  • There exist valid country assignment of people for input.

Examples

  1. {0,2,3,0,0}
    Returns: "Sufficient"
    The first two people must be from the same country. The last three people must also be from the same country. Thus, the only possible sequence of answers is {2,2,3,3,3}.
  2. {0,2,0}
    Returns: "Insufficient"
    There are still two different sequences of answers that are consistent with the reporter's information: the answers can be either {1,2,2} or {2,2,1}.
  3. {0,3,0,0,3,0}
    Returns: "Sufficient"
  4. {0,0,3,3,0,0}
    Returns: "Insufficient"
  5. {2,2,0,2,2}
    Returns: "Sufficient"
Back to all problems