Connection Status:
Competition Arena > SymmetricImage
TCO18 India Fun · 2018-04-20 · by erinn · Simple Search, Iteration
Class Name: SymmetricImage
Return Type: int
Method Name: countDirections
Arg Types: (vector<string>)
Problem Statement

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.

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
0)
{ "AAA",
  "BBB" }
Returns: 1

The image is symmetric horizontally, but not vertically.

1)
{ "ABCDE",
  "ABCDE",
  "ABCDE" }
Returns: 1

Here we have vertical symmetry only.

2)
{ "ABA",
  "CDC",
  "ABA" }
Returns: 2

Symmetry in both directions.

3)
{ "ABC" }
Returns: 1

With only a single row of pixels, we are guaranteed vertical symmetry.

4)
{ "AB",
  "CD" }
Returns: 0

No symmetry at all.

Submissions are judged against all 18 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SymmetricImage with a public method int countDirections(vector<string> image) · 18 test cases · 2 s / 256 MB per case

Submitting as anonymous