Official algorithmic problem description and constraints.
You have been given a matrix π of size π by π, containing a permutation of integers from 1 to πβ π.
A permutation of π integers is an array containing all numbers from 1 to π exactly once. For example, the arrays [1], [2,1,3], [5,4,3,2,1] are permutations, while the arrays [1,1], [100], [1,2,4,5] are not.
A matrix contains a permutation if, when all its elements are written out, the resulting array is a permutation. Matrices [[1,2],[3,4]], [[1]], [[1,5,3],[2,6,4]] contain permutations, while matrices [[2]], [[1,1],[2,2]], [[1,2],[100,200]]do not.
You can perform one of the following two actions in one operation:
You can perform any number of operations.
You are given the original matrix π and the matrix π. Your task is to determine whether it is possible to transform matrix π into matrix π using the given operations.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.