TopcoderArchiveVisit Topcoder
TCO20 Apr 2018
TCO18 India

SymmetricImage

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given an image described in String[] image. Different characters in image represent pixels of different colors. (For example, each 'A' is a red pixel, each 'B' is a blue pixel, and so on.) You want to determine if the image is symmetric, either horizontally or vertically. Return 0 if there is no symmetry, 1 if the image is symmetric in only a single direction, or 2 if it is symmetric both horizontally and vertically.

Definition

Class:
SymmetricImage
Method:
countDirections
Parameters:
String[]
Returns:
int
Method signature:
int countDirections(String[] image)
(be sure your method is public)

Constraints

  • image will contain between 1 and 50 elements, inclusive.
  • Each element of image will contain between 1 and 50 characters, inclusive.
  • Each element of image will be the same length.
  • Each character of each element of image will be an uppercase letter ('A'-'Z').

Examples

  1. { "AAA",
      "BBB" }
    Returns: 1
    The image is symmetric horizontally, but not vertically.
  2. { "ABCDE",
      "ABCDE",
      "ABCDE" }
    Returns: 1
    Here we have vertical symmetry only.
  3. { "ABA",
      "CDC",
      "ABA" }
    Returns: 2
    Symmetry in both directions.
  4. { "ABC" }
    Returns: 1
    With only a single row of pixels, we are guaranteed vertical symmetry.
  5. { "AB",
      "CD" }
    Returns: 0
    No symmetry at all.
Back to all problems