TopcoderArchive
Archive
Algorithm problem

PalinBox

Problem statement, definition, constraints, and public examples.

Problem Statement

You will be given a rectangular box of letters as a String[] (each element is a row). We want to change box so that every column and every row is a palindrome. That is, reading a row left-to-right is the same as right-to-left and reading a column top-to-bottom is the same as bottom-to-top. Return the fewest number of cells in box that need to be changed to achieve this effect.

Definition

Class:
PalinBox
Method:
getMin
Parameters:
String[]
Returns:
int
Method signature:
int getMin(String[] box)
(be sure your method is public)

Notes

  • box will contain between 2 and 50 elements, inclusive.
  • Each element of box will contain between 2 and 50 characters, inclusive.
  • Each character in box will be a capital letter ('A'-'Z').
  • Each element of box will contain the same number of characters.

Constraints

    Examples

    1. {
      "ABA",
      "BAB",
      "ABA"
      }
      Returns: 0
      No changes needed.
    2. {
      "AB",
      "CD"
      }
      Returns: 3
      We can solve this one by making every cell 'A'.
    3. {
      "ABC",
      "DEF",
      "GHI"
      }
      Returns: 5
      We can change the input to the following box: { "ABA", "DED", "ABA" }
    4. {
      "ABCD",
      "EFGH",
      "IJKL",
      "MNOP"
      }
      Returns: 12
    5. {
      "ZFF",
      "YYS",
      "VSH",
      "CXT",
      "WVR",
      "TPO",
      "BPR",
      "VQM",
      "IXV",
      "KMN"
      }
      Returns: 19
      The input need not be square.
    6. {"BBE", "EAE", "FCD"}
      Returns: 4
    Back to all problems