100 Days LeetCode Challenge: Matrix Similarity After Cyclic Shifts

✅ Day 84 of 100 Days LeetCode Challenge Problem: 🔹 #2946 – Matrix Similarity After Cyclic Shifts 🔗 https://lnkd.in/g3uy6WKa Learning Journey: 🔹 Today’s problem was about checking if a matrix remains the same after applying cyclic shifts k times. 🔹 Instead of handling even and odd rows separately, I simplified the logic by focusing on the final shifted state. 🔹 I used modulo (k % n) to reduce unnecessary full rotations. 🔹 For each row, I generated its left cyclic shift using slicing: • row[k % n:] + row[:k % n] 🔹 Then, I directly compared the shifted row with the original row. 🔹 If any row doesn’t match, return False; otherwise, True. Concepts Used: 🔹 Modular Arithmetic 🔹 Array Slicing 🔹 Matrix Traversal Key Insight: 🔹 Full rotations don’t change the array, so reducing k using modulo is critical. 🔹 Direct row comparison after a single computed shift avoids repeated simulation and keeps the solution concise. Complexity: 🔹 Time: O(n × m) 🔹 Space: O(m) #LeetCode #Algorithms #DataStructures #CodingInterview #100DaysOfCode #SoftwareEngineering #Python #ProblemSolving #LearningInPublic #TechCareers

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories