LeetCode Entry
1886. Determine Whether Matrix Can Be Obtained By Rotation
Rotate matrix
1886. Determine Whether Matrix Can Be Obtained By Rotation easy substack youtube

Join me on Telegram
https://t.me/leetcode_daily_unstoppable/1305
Problem TLDR
Rotate matrix #easy
Intuition
Rotate 4 times and check deep equals.
Approach
- or just check 4 counters of equal values, should be n^2
Complexity
-
Time complexity: \(O(n^2)\)
-
Space complexity: \(O(n^2)\)
Code
// 14ms
fun findRotation(m: Array<IntArray>, t: Array<IntArray>) =
generateSequence(m) { m ->
Array(m.size){ y -> IntArray(m.size) { x -> m[m.size-1-x][y] }}
}.take(4).any(t::contentDeepEquals)
// 0ms
pub fn find_rotation(m: Vec<Vec<i32>>, t: Vec<Vec<i32>>) -> bool {
let n = m.len(); iterate(m, |c| (0..n).map(|i| (0..n).map(|j|
c[n-1-j][i]).collect()).collect()).take(4).any(|c| c == t)
}