Check Whether Quarter-Turns Match a Target Matrix

Quick Overview

Check Whether Quarter-Turns Match a Target Matrix. Two square binary matrices mat and target have the same dimensions. Return whether rotating mat by any number of ninety-degree turns, including zero, can make it equal to target.

Check Whether Quarter-Turns Match a Target Matrix

Company: Bloomberg

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Two square binary matrices `mat` and `target` have the same dimensions. Return whether rotating mat by any number of ninety-degree turns, including zero, can make it equal to target. ```cpp class Solution { public: bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target); }; ``` ### Examples **Example 1:** ```text mat = [[1,0],[0,0]], target = [[0,1],[0,0]] Output: true Explanation: One clockwise turn moves the lone 1 from top-left to top-right. ``` **Example 2:** ```text mat = [[1,0],[0,1]], target = [[1,1],[0,0]] Output: false Explanation: Rotation preserves the opposite-corner relationship of the two ones. ``` ### Constraints - `n == mat.length == target.length`. - Every row in either matrix also has length n. - `1 <= n <= 10`. - Entries in both matrices are 0 or 1. ### Clarifying Questions Only rotations are permitted; no reflection or arbitrary rearrangement is allowed. Already equal matrices return true. ```hint Inspect the structure Which transformations are allowed, and does a match before any turn count? ``` ### Reasoning checkpoints - Cover every permitted turn count, including zero, without admitting reflection. - Distinguish equal value counts from equality after a legal rotation. ### Optional extensions How would allowing reflections enlarge the set of orientations to examine?

Overview: Check Whether Quarter-Turns Match a Target Matrix. Two square binary matrices mat and target have the same dimensions. Return whether rotating mat by any number of ninety-degree turns, including zero, can make it equal to target.

Bloomberg logo
Bloomberg
Source window: 0–3 months · as of Oct 21, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Two square binary matrices mat and target have the same dimensions. Return whether rotating mat by any number of ninety-degree turns, including zero, can make it equal to target.

class Solution {
public:
    bool findRotation(vector<vector<int>>& mat, vector<vector<int>>& target);
};

Examples

Example 1:

mat = [[1,0],[0,0]], target = [[0,1],[0,0]]
Output: true
Explanation: One clockwise turn moves the lone 1 from top-left to top-right.

Example 2:

mat = [[1,0],[0,1]], target = [[1,1],[0,0]]
Output: false
Explanation: Rotation preserves the opposite-corner relationship of the two ones.

Constraints

  • n == mat.length == target.length .
  • Every row in either matrix also has length n.
  • 1 <= n <= 10 .
  • Entries in both matrices are 0 or 1.

Clarifying Questions Guidance

Only rotations are permitted; no reflection or arbitrary rearrangement is allowed. Already equal matrices return true.

Reasoning checkpoints

  • Cover every permitted turn count, including zero, without admitting reflection.
  • Distinguish equal value counts from equality after a legal rotation.

Optional extensions

How would allowing reflections enlarge the set of orientations to examine?