[Question]
  [
# Input
The board: A 2D container (matrix, list of lists, etc.) of letters like:
```
  ["B", "C", "C", "C", "C", "B", "B", "C", "A", "A"],
  ["B", "A", "C", "B", "B", "A", "B", "B", "A", "A"],
  ["B", "C", "B", "C", "A", "A", "A", "B", "C", "B"],
  ["B", "B", "B", "A", "C", "B", "A", "C", "B", "A"],
  ["A", "A", "A", "C", "A", "C", "C", "B", "A", "C"],
  ["A", "B", "B", "A", "A", "C", "B", "C", "C", "C"],
  ["C", "B", "A", "A", "C", "B", "B", "C", "A", "A"]
```
If you choose a list of lists you may assume that all of the sublists are of the same length.
# Rules
* To make a valid rectangle you need all rectangle corners with the same 'letter'.
* Example, look the *sample board with* **X** bellow. You can see 'X' on (1,0) also on (4,0) also on ( 1,3) and on (4,3) then you have the rectange [1,0,4,3] that means from (1,0) to (4,3):
*Sample board with* **X**:
```
  ["B", "X", "C", "C", "X", "B", "B", "C", "A", "A"],
  ["B", "A", "C", "B", "B", "A", "B", "B", "A", "A"],
  ["B", "C", "B", "C", "A", "A", "A", "B", "C", "B"],
  ["B", "X", "B", "A", "X", "B", "A", "C", "B", "A"],
  ["A", "A", "A", "C", "A", "C", "C", "B", "A", "C"],
  ["A", "B", "B", "A", "A", "C", "B", "C", "C", "C"],
  ["C", "B", "A", "A", "C", "B", "B", "C", "A", "A"]
```
* The goal is to find the rectangle or one of the rectangles with the largest area, calculated by (right-left+1)\*(bottom-top+1)
* If there are multiple rectangles with the same maximum area, output any one. Optionally the one with (top coordinate, left coordinate, right coordinate, bottom coordinate) lexicographically smallest.
* Rectangles must have edges parallel to the board's edge.
* Each letter is a printable ASCII char from A to Z (both included).
# Output
The output should be the left-up and right-down positions of the largest area rectangle corners. For the first sample "board" the big square is the yellow one:
[![enter image description here](https://i.stack.imgur.com/ZIkkF.png)](https://i.stack.imgur.com/ZIkkF.png)
And the answer should be:
> 
> [1, 1, 8, 4]
> 
> 
> 
### A second example test case
An input of:
```
["C", "D", "D", "D", "A", "A"],
["B", "D", "C", "D", "A", "A"],
["B", "D", "D", "C", "A", "C"],
["B", "D", "B", "C", "A", "C"]
```
Should yield one of these three coordinate lists identifying an area six rectangles:
> 
> [1, 0, 2, 2]  
> 
> [1, 0, 3, 1]  
> 
> [3, 2, 5, 3]
> 
> 
> 
This question is posted on Stack Overflow with title: [How to find the largest rectangle in a 2D array formed by four identical corners?](https://stackoverflow.com/questions/49708412/how-to-find-the-largest-rectangle-in-a-2d-array-formed-by-four-identical-corners) and with this rude JS solution (I can say "rude" because is my code ;) :
Ok, is my first post, be tolerant with me please. I will change all you say to improve the quiz.
  
[Answer]
# [Python 2](https://docs.python.org/2/), ~~148~~ 130 bytes
```
lambda x,e=enumerate:min(((a-c)*(d-b),b,a,d,c)for a,y in e(x)for c,k in e(x)for b,g in e(y)for d,h in e(y)if g==h==k[b]==k[d])[1:]
```
[Try it online!](https://tio.run/##fZDLCoMwEEX3/YrBVVLGRbsUsrD5DJtFYuIDaxSxoF9vqdpiNO3mMgfmXIZpx75o7HXK2H16yFppCQMaZuyzNp3sTVSXlhAiw5SeiQ4VRYUSNaY0azqQOEJpwZBhxhSrLSrMFxxn1Fh8sMwgZ6xgrEqUeKcWNLlEYmq70vaQkSQJbgFCwD1x@8aM8RICTwCrFXt2Yw@6Fvf2Ouq6srV2lfw3rtaul7vTwd9ah/OPV3PH4n@F4w8FnV4 "Python 2 – Try It Online")
[Answer]
# [Retina](https://github.com/m-ender/retina/wiki/The-Language), ~~163~~ 162 bytes
```
Lw$`(?<=(.*\n)*((.)*))(?=(.))((.)*(?<=(.*))\4)((.*\n)*((?>(?<-3>.)*)(?=\4)(?>(?<-6>.)*))\4)?
$.7,$#1,$.2,-$.($5$#9*$5),$.2,$#1,$.7,$.($#1*_$#9*
4{N`
)m`^.*?,
0G`
```
[Try it online!](https://tio.run/##LYqxCsIwFEX3/EbekBfSYLRVBG1IE3ARv6BoHBwc7CCCgx8f32s6Xe455/34PKe7K@X8haz84aisHifUSlnUiMoToOG3WMSxZbBkvifebHrOqWZX0XZGHHsBdmdAOgN2bRqwCjqQew0dzqQaKkhIp2/sRPu7ZIGvfLXaGyFWp1xKTCmFIIYU66QYIs1A8wc "Retina – Try It Online") Edit: Saved 1 byte because the trailing `)` matching the `$.(` is implicit. Explanation:
```
Lw$`(?<=(.*\n)*((.)*))(?=(.))((.)*(?<=(.*))\4)((.*\n)*((?>(?<-3>.)*)(?=\4)(?>(?<-6>.)*))\4)?
```
This regular expression matches rectangles. The groups are as follows: 1) Top row (as capture count) 2) Left column (as length) 3) Balancing to ensure the left corners align 4) Letter for the corners 5) Width + 1 (as length) 6) Balancing to ensure the right corners align 7) Right column (as length) 8) unused 9) Height (as capture count). The `w` option ensures that all possible widths of rectangles are matched for each given top left corner. The `$` options lists the results using the following substitution pattern.
```
$.7,$#1,$.2,-$.($5$#9*$5),$.2,$#1,$.7,$.($#1*_$#9*
```
The substitutions are as follows: The right column, the top row, the left column, the negation of the area of the rectangle (literally calculated as the length of repeating the width string by one more than height number of times), the left column, the top row, the right column, followed by an expression that evaluates to the bottom row (a capture would have cost 12 bytes plus I've run out of single-digit variables). The first four captures represent the sort order in order of priority. As Retina sorts stably, a multicolumn sort can be established by sorting by each sort column in turn from least to greatest priority. (The area must be sorted in descending order, so a single string sort cannot be used.)
```
4{N`
```
Four numeric sorts are then performed.
```
)m`^.*?,
```
The sort column is then deleted after each sort.
```
0G`
```
The first entry is therefore now the desired result.
Note: The restriction on the choice of rectangle of a given area has since been relaxed and the following ~~144~~ 143-byte version prefers a wider rather than a taller rectangle:
```
Lw$`(?<=(.*\n)*((.)*))(?=(.))((.)*(?<=(.*))\4)((.*\n)*((?>(?<-3>.)*)(?=\4)(?>(?<-6>.)*))\4)?
-$.($5$#9*$5);$.2,$#1,$.7,$.($#1*_$#9*
N`
0G`
.*;
```
[Try it online!](https://tio.run/##LYpBCsIwEEX3c43MIhPSYNQqUm1IE3AjnqDQuHDhpgsRPH6csV09/nv//fy85oev9fbFosP5op0ZZzJaOzJEOrBgyFor0bgXsd5Cz77Z9XLnt7RFHf5KzgEadBpbVCeDLXXothaVt@iOVoLyZpIG9wKbawFnOqg15ZxjhCGnBTnFxBgYPw "Retina – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), (27?) ~~29~~ 28 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
27 if 1-based indexing is allowed - remove trailing `’`
```
Fṙ1s2;Uœị³EaZI‘P
ZLpLŒċÇÞṪF’
```
A full program.
**[Try it online!](https://tio.run/##y0rNyan8/9/t4c6ZhsVG1qFHJz/c3X1os2tilOejhhkBXFE@BT5HJx3pPtx@eN7DnavcHjXM/P//f3S0kpOSjoKSMxbCCU6AuY4QIlaHSwGqyRGLUkcsXBRNzlhNRdEJVYKkCc1AZ9xciCY0U51RWRjakTRhOB3Tyc7ImpzxqscMvVgA "Jelly – Try It Online")** (or see the other [test case](https://tio.run/##y0rNyan8/9/t4c6ZhsVG1qFHJz/c3X1os2tilOejhhkBXFE@BT5HJx3pPtx@eN7DnavcHjXM/P//f3S0krOSjoKSCyrhCCFidbgUopWc4MLOhBQgVDlCWOgKnDAUxAIA "Jelly – Try It Online"))
### How?
```
Fṙ1s2;Uœị³EaZI‘P - Link 1, areaOrZero: list of pairs [[b,l],[t,r]]
F                - flatten the input                 [b,l,t,r]
 ṙ1              - rotate left one                   [l,t,r,b]
   s2            - split into twos                   [[l,t],[r,b]]
      U          - upend the input                   [[l,b],[r,t]]
     ;           - concatenate                       [[l,t],[r,b],[l,b],[r,t]]
         ³       - program's input
       œị        - multidimensional index into
          E      - all equal?                       X
            Z    - transpose the input              [[b,t],[l,r]]
           a     - logical AND (vectorises)         (if not X we now have [[0,0],[0,0]]
             I   - incremental differences          [t-b,r-l] (or [0,0] if not X)
              ‘  - increment (vectorises)           [t-b+1,r-l+1] (or [1,1] if not X)
               P - product                          area (or 1 if not X)
ZLpLŒċÇÞṪF’ - Main link: list of lists
Z           - transpose the input
 L          - length
   L        - length of the input
  p         - Cartesian product
    Œċ      - pairs with replacement
       Þ    - (stable) sort by:
      Ç     -   last link (1) as a monad
        Ṫ   - tail (note that the rightmost pre-sort represents the bottom-right 1x1
            -       so cannot be superseded by a non-matching rectangle)
         F  - flatten
          ’ - decrement (vectorises) (to get to 0-based indexing)
```
[Answer]
# [Perl 6](https://github.com/nxadm/rakudo-pkg), ~~83~~ 73 bytes
```
{([X] (^$^a[0]X ^$a)xx 2).max:{[eq] $a[.[*;1];.[*;0]]and[*] 1 X-[Z-] $_}}
```
[Try it online!](https://tio.run/##hZDLDoJADEX3fEVDiAECBFy4kLiA@hETm2ImUVbiAzcQ47cjiDK8optO79x7Os1cj/lpVWUlLFLYVA@TBIOZGIkknwUkhrSKApaWl8li/aDjjcGQ5JEdBhw2h88szweyGQIQLu3cOrB/Pqu7LCE1jb0F6SXXSCMddQf07bBEbWGn9uPuFv/4KhS13ciPJ77WJL4Z0dnYyXiG678bdZZKRjOyz@DszAH4iShGDMeNJPbkmxnNxGGHY1oxk7Wn@2KPwZ/x6b9pHFYv "Perl 6 – Try It Online")
Returns a list of lists `((x0 y0) (x1 y1))`.
### Explanation
```
{
  ([X]                   # Cross product of corner pairs.
    (^$^a[0]             # Range of x coords.
     X                   # Cross product of coords.
     ^$a                 # Range of y coords.
    )xx 2                # Duplicate list.
  ).max:                 # Find maximum of all ((x0 y0) (x1 y1)) lists
  {                      # using the following filter.
    [eq]                 # All letters equal?
      $a[.[*;1];.[*;0]]  # Multidimensional subscript with y and x coord pairs.
    and                  # Stop if false.
    [*]                  # Multiply
      1 X-[Z-] $_        # for each axis 1 - (c0 - c1) == c1 - c0 + 1.
  }
}
```
[Answer]
# [Haskell](https://www.haskell.org/), 144 bytes
```
import Data.Array
o=assocs
f r=snd$maximum[((c-a+1)*(d-b+1),[a,b,c,d])|((a,b),x)<-o r,((c,d),y)<-o r,x==y,r!(a,d)==r!(c,b),x==r!(a,d),a<=c,b<=d]
```
[Try it online!](https://tio.run/##PY7NasMwDMfveQqt9GBvyugug0F0sN23KD2occtM4yTYGSTQd8/kdMwY6//xA/mb8/3adesa4jikCY488btJiZdqIM55aHN1g0S59/vIc4g/8aRUW/Pbh35Vvr7IxBPjBVv0Z/1QSrTGWTf1AAkFRa9x@bMz0YLpRRiviUS0G7zJkiE3JFFD/rxmjmN3BYIu5Gn7ESh1wING9YWfWsPOyjHGOeOssdY5cVa0eFOi52u2onCClOv@20I7s6sih57GFPoJ9nCD5@L1Fw "Haskell – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 24 bytes
```
XLṭLp`€p/⁺œị€EɗÐfI‘PɗÞ0Ṫ
```
[Try it online!](https://tio.run/##RZC9TsMwFIX3PMWVGNpKQfw8AFISlx8pAyNVVQlTbhsX145iR1W3wtKBBYkBBsQDoDJDQWKpGHiM5EXCTSKCB/v4@pxP13eCUs6L4izM1q9hfJ7frOKd/Prj@z77vKVL9@dhczc6yRePp6Sed7P1S7FZ0kO2/qK9B9n7W754gpAbC1KoK2hvlh0XeBzLOZCDDyMXUoXk57IpTLRQcDEHhTMKIbR7naLowxZMU2lFLBEsEnDIDRqXXHgJHEZaW0zA6pq@jYRynH7L83y/5bj1OSDIPiQ4tFyNJRqYCRuB4VMEniB3XAoEjDHPKyM@CxrFAi@olV@qQWX1/ICVxe7h0XHFVvofXrNLLBzAXu2vVt3NX7YS3UqxhtN8VMdWTGk0RsvUCq0MmIgnQo3BRjQGTZ4RTUInChPHGfwC "Jelly – Try It Online")
`⁺` proves to be useful.
Output format: *[top,bottom],[left,right]*. 1-indexing.
[Answer]
# JavaScript (ES6), 121 bytes
*-1 byte thanks to @l4m2*  
*-1 byte thanks to @tsh*  
*+2 bytes to comply with the new rectangle scoring rule*
Takes input as a matrix of strings. Returns 0-indexed coordinates: **[x0, y0, x1, y1]**.
```
a=>a.map(b=(r,y)=>r.map((v,x)=>a.map((R,Y)=>R.map((V,X)=>V+R[x]+r[X]!=v+v+v|(A=(x+~X)*(y+~Y))<b||(o=[x,y,X,Y],b=A)))))&&o
```
[Try it online!](https://tio.run/##fZFNasMwEIX3PoXrRRhF01wgUUCWT@BFsBFayGlSWpIoOMXYYHJ113V@ZamRYNBD73uMRt@60qd1@XX8eT@Yj023ZZ1mSz3b6yMUDEpsCFuWg4QKa3K7gxTzXqQXscKsFyuaylrRUmbqjVW03y1wBjU9Z2QKDT3nhCyKtgXDZI0NZpgrLBgnf2syMd3aHE5mt5ntzCdsQQZhKKM4wjASnhLfyyD5pSh8UNzj5R5pU8Kba6FXyzM1ihT/yys1yhX2yeGfKad9t2thUeIl4M4wUITMA99vDLbELp4ZJvfIl45k/HLHETuOobfuFw "JavaScript (Node.js) – Try It Online")
[Answer]
# [APL (Dyalog Classic)](https://www.dyalog.com/), 38 bytes
```
a⊃⍨⊃⍒×/1+-/↑2 2∘⍴¨a←⍸≢¨↑∘.(∩¨)⍨∘.∩¨⍨↓⎕
```
[Try it online!](https://tio.run/##bU29CsIwEN7vKRwVqdW@QXJ5kVCpFAoVnJyFWsWIP4hODk5xd3BxqW9yL1Lv4qjhyPeT777YaRGN57YoJ1Fa2NksT1vanvKSqt0QqF5mraX1gpwP9@F9jkf9KKZqn3QSqi/kHo23HCb3pNWt8fzC9qBL9b3xPdljFYTw6sjlLde2GUhy8yJ3/R3QyEdrVAq0YqJ4mKI4igG0Fl8G2EGFIiDEUJYBAwsN8O8vQGOMdBr8guESBt7ADw "APL (Dyalog Classic) – Try It Online")
[Answer]
# Java 8, ~~208~~ 205 bytes
```
m->{int r=0,R[]={},i=m.length,j,y,z,u,t,T;for(;i-->0;)for(j=m[i].length;j-->0;)for(y=i*j;y-->0;)if((T=m[i][j])==m[u=y/j][z=y%j]&T==m[i][z]&T==m[u][j]&r<(t=(i-u)*(j-z))){r=t;R=new int[]{z,u,j,i};}return R;}
```
Can definitely be golfed.. I now use the most obvious approach of using ~~four~~ three nested for-loops.
-3 bytes thanks to *@ceilingcat* combining the inner loops of rows and columns into a single loop.
**Explanation:**
[Try it online.](https://tio.run/##vZLBToQwEIbvPkVjomlNQe@1JlCuelj3QEI4VGS1FbqmFA1LePZ1Cqte7B5MlAxh6P9N6fyMlm8y0o8v@6qRXYdupTLjCULKuNpuZFWjO/86LxQlqnD1LG1RQtoSBsIEN0TnpFMVukMGcbRvo5sReGT5FV0VJR8nqngbN7V5cs9U04HuaE8dXbPN1mKmoujmihGfa94WqjyQTH8LA1cXmg3LgtpgvJ7JQpeEQ9bz4VKXxY4PZ7o8X/NF3B3S3nPn9ho7jlXUkwusox0hZLTcsRU39fvS3uiPpama2GRr11uDVmzas6XF1/6hgRYPnb5t1SNqwSx876wyT0UpyWLU/dC5uo23vYtfQXGNwRo8jnunmjixVg5d7LZLFTZxhf3nP11dtkDoNBVwpalIklOgBchzKSb0i0hATyDChPD1CTyCROp38REioF4kwjNBwh9B@POGCDEDP/QyAxP8CBZyLqz8wlORZdkRtzJxVM1E2IM0S0Pq/7WX50Lk3ub8T0cmT5P8z0cm/xyZ/NjITCfT/gM)
```
m->{                         // Method with char-matrix parameter and int-array return-type
  int r=0,                   //  Largest area found, starting at 0
      R[]={},                //  Result coordinates, starting empty
      i=m.length,j,          //  x,y indices of the first corner
      y,z,                   //  x,y indices of the second corner
      u,t,T;                 //  Temp integers to reduce bytes
  for(;i-->0;)               //  Loop `i` over the rows
    for(j=m[i].length;j-->0;)//   Inner loop `j` over the columns
      for(y=i*j;y-->0;)      //    Inner loop over the rows and columns
        if((T=m[i][j])==m[u=y/j][z=y%j]
                             //      If the values at coordinates [i,j] and [y,z] are equal
           &T==m[i][z]       //      as well as the values at [i,j] and [i,z]
           &T==m[u][j]       //      as well as the values at [i,j] and [y,j]
           &r<(t=(i-u)*(j-z))){
                             //      And the current area is larger than the largest
          r=t;               //       Set `r` to this new largest area
          R=new int[]{z,u,j,i};}
                             //       And save the coordinates in `R`
  return R;}                 //  Return the largest rectangle coordinates `R`
```
]