Flipping Square Submatrix Vertically in Java

🚀 Day 538 of #750DaysOfCode 🚀 Today I solved Flip Square Submatrix Vertically (LeetCode 3643) using Java. 🔹 Problem Summary: Given a matrix and a square submatrix defined by top-left corner (x, y) and size k, we need to flip that square vertically. Flipping vertically means reversing the order of rows inside the selected k × k submatrix while keeping the rest of the matrix unchanged. 🔹 Approach Used: I used a two-pointer approach to swap rows inside the square: • One pointer at the top row • One pointer at the bottom row • Swap elements column by column inside the square • Move pointers towards the center This way, the submatrix gets flipped vertically in-place without extra space. 🔹 Key Concepts Learned: ✅ Matrix traversal ✅ Submatrix manipulation ✅ Two-pointer technique ✅ In-place swapping ✅ Clean implementation in Java Small problems like this help in mastering matrix operations, which are very common in coding interviews. #750DaysOfCode #Day538 #LeetCode #Java #DSA #Algorithms #CodingChallenge #Matrix #ProblemSolving #Consistency

  • graphical user interface, text

To view or add a comment, sign in

Explore content categories