Hello, Everyone!
I am Somuya Khandelwal, and today marks Day 1 of Week 2 in my journey of competitive programming. After wrapping up a productive first week, I dived into Week 2 with a focus on Matrix problems. Working with matrices is a core skill in programming that tests your logical thinking, spatial awareness, and ability to write optimized code.
Today's focus was on solving two medium-level problems on LeetCode, each offering a unique perspective on handling 2D arrays and applying specific algorithms for matrices.
What I Worked On Today
-
Valid Sudoku (Medium Difficulty)
This problem involved verifying the validity of a given 9x9 Sudoku grid by ensuring it adhered to the following conditions:
- Each row must contain the digits 1 to 9 with no repetitions.
- Each column must contain the digits 1 to 9 with no repetitions.
- Each 3x3 sub-box must also contain the digits 1 to 9 with no repetitions.
What I Learned:
- Leveraged hash sets for tracking unique elements in rows, columns, and sub-boxes.
- Implemented nested loops efficiently to traverse the grid while keeping complexity low.
- Developed a better understanding of managing overlapping constraints across multiple dimensions.
-
Spiral Matrix (Medium Difficulty)
The challenge was to extract and return all elements of a 2D matrix in spiral order.
- Traversed the matrix layer by layer while dynamically adjusting boundaries to avoid revisiting elements.
What I Learned:
- Gained experience in handling dynamic boundary conditions for traversals.
- Improved my ability to tackle edge cases, such as matrices with a single row or column.
- Enhanced my systematic approach to navigating and manipulating 2D arrays.
Key Takeaways from Today
-
Techniques for Matrix Traversal:
- Efficiently handling 2D grids requires careful planning, especially for problems like Spiral Matrix where dynamic boundary management is crucial.
-
Validation Using Hash Sets:
- Hash sets are highly effective for ensuring uniqueness in rows, columns, and sub-boxes, as seen in Valid Sudoku. They provide constant-time checks, improving overall efficiency.
-
Edge Case Awareness:
- It's vital to account for edge cases like empty matrices or single-row/column scenarios to ensure solutions are robust.
Reflection
The Valid Sudoku problem was a great exercise in managing constraints across rows, columns, and sub-boxes simultaneously. Debugging overlapping conditions was challenging but rewarding. On the other hand, the Spiral Matrix problem required a clear, step-by-step approach to traversal, making it satisfying to solve.
Starting the week with these matrix problems has boosted my confidence, and I’m eager to tackle more advanced challenges.
What’s Next?
Tomorrow, I’ll continue exploring matrix manipulation with problems like Rotate Image, Set Matrix Zeroes, and Game of Life. These tasks will deepen my understanding of in-place algorithms and efficient matrix transformations.
Thanks for reading! Stay tuned for updates as I continue this exciting journey of learning and growth in competitive programming.
Best,
Somuya
Top comments (0)