TopcoderArchive
Archive
Algorithm problem

Minors

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider an m x n matrix. You remove some of its rows and some of its columns to get a 2 x 2 matrix. After that, you compute the determinant of this small matrix. Recall that the determinant of a 2 x 2 matrix is

| a b |
| c d | = ad - bc

Such a determinant is called a minor of order 2 of the initial matrix.

You are given a matrix as a String[] matrix. The i-th element of matrix contains n digits that represent the values of the i-th row of the given matrix. Return the number of distinct values that a minor of order 2 of the given matrix can have.

Definition

Class:
Minors
Method:
countMinors
Parameters:
String[]
Returns:
int
Method signature:
int countMinors(String[] matrix)
(be sure your method is public)

Constraints

  • matrix will contain between 2 and 10 elements, inclusive.
  • Each element of matrix will contain between 2 and 10 characters, inclusive.
  • All elements of matrix will contain the same number of characters.
  • Each element of matrix will contain only digits ('0'-'9').

Examples

  1. {"012", "120", "210"}
    Returns: 5
    In this example the possible values of the minor of order 2 are 0, -1, -2, -3 and -4.
  2. {"00", "00"}
    Returns: 1
    The only value that you can get here is 0.
  3. {"012", "345", "678"}
    Returns: 3
  4. {"0123456789", "1234567890"}
    Returns: 17
Back to all problems