TopCoder problem "VegetableField" used in TCHS SRM 36 (Division I Level One)



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

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

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8059

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10774&pm=8059

Writer:

mateuszek

Testers:

PabloGilberto , brett1479 , Olexiy , ivan_metelsky

Problem categories:

Brute Force, Simple Search, Iteration