TopcoderArchiveVisit Topcoder
Archive
Algorithm problem

VegetableField

Problem statement, definition, constraints, and public examples.

Problem Statement

We want to buy a rectangular plot on a rectangular vegetable field. We want our plot to be as big as possible, but we only have the resources to grow a maximum of 2 different kinds of vegetables on it. You are given a String[] field, where each character represents a square in the field. All squares are of equal size. The j-th character of the i-th element of field denotes the kind of vegetable that grows in the square at row i, column j - it's an uppercase letter ('A' - 'Z'), where each letter denotes a different kind of vegetable. Return the area of the biggest plot we can buy.

Definition

Class:
VegetableField
Method:
biggestPlot
Parameters:
String[]
Returns:
int
Method signature:
int biggestPlot(String[] field)
(be sure your method is public)

Constraints

  • field will contain between 2 and 20 elements, inclusive.
  • Each element of field will contain between 2 and 20 characters, inclusive.
  • All elements of field will contain the same number of characters.
  • Each character in each element of field will be an uppercase letter ('A' - 'Z').

Examples

  1. { "AAA",
      "AAA",
      "AAA"  }
    Returns: 9
    Only one type of vegetable grows here so we can buy the whole field.
  2. { "ABCDEFGH",
      "IJKLMNOP",
      "QRSTUVWX"  }
    Returns: 2
    We can buy only 2 adjacent squares and nothing more.
  3. { "AAAA",
      "ABBC",
      "BBCA",
      "DCAA"  }
    Returns: 6
  4. { "AUFLKNCSLKX",
      "OWVGWXGHKFB",
      "MUFZEELAWOR",
      "CZCGHXVGWDW",
      "EPNSDSJSKWT",
      "APULZGHXMEK",
      "UVMQQUFMYYQ",
      "XWLMVXKSENF",
      "KGZJUDQOAXA",
      "UKIBGOSXSZL"  }
    Returns: 4
  5. { "BDCDCCCCBED",
      "ECEAADCEACA",
      "AABEABBACBB",
      "CEBEDDDDBDE",
      "DBCACCABBDE",
      "CCEECDCECBB",
      "CCADACEDDCE",
      "DDCEAACAEBB",
      "CACCEEAACCA",
      "DBAACCEEACD",
      "DDBAACBEEAE"  }
    Returns: 8
Back to all problems