← Back to challenges

Identical Row and Column?

PythonHardarraysvalidation

Instructions

Write a function that returns True if there exists a row that is identical to a column in a 2-D matrix, otherwise False.

To illustrate:

[
  [1, 2, 3, 4],
  [2, 4, 9, 8],
  [5, 9, 7, 7],
  [6, 8, 1, 0]
]

# 2nd row + 2nd column are identical: [2, 4, 9, 8]

Examples

has_identical([
  [4, 4, 4, 4],
  [2, 4, 9, 8],
  [5, 4, 7, 7],
  [6, 4, 1, 0]
]) ➞ True

has_identical([
  [4, 4, 9, 4],
  [2, 1, 9, 8],
  [5, 4, 7, 7],
  [6, 4, 1, 0]
]) ➞ False

has_identical([
  [4, 4]
  [2, 1]
]) ➞ False

has_identical([
  [4, 2]
  [2, 1]
]) ➞ True

Notes

Non-square matrices should return False.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.