HackerRank flippingMatrix Challenge in Python
After some time and research I came to the conclusion that this is more of a logical problem than a programming one.
The problem it selt you can found there https://www.hackerrank.com/challenges/flipping-the-matrix/problem
Sure, you can use brute force and solve the problem, but what’s good for a 4x4 array, a 100x100 array can start to get a little hard to sustain. The following solution works, but it is not the way to go.
First, I found a video of this gentleman. I didn’t understand anything, but he draws nicely and seems like a nice guy, and his “logical problem” is so euphonious that I thought that must be where the solution is going.
On the hackerrank forum itself, there was also a discussion on this topic and I found a nice hand-drawn picture that shows what positions can actually be taken into account (following the lead of the gentleman from YouTube).
In fact — only the top square and fields that can be swapped in it count.
Here’s a drawing of Julia Este
And here is its implementation in Python.
Incredibly simple, right? I hope you enjoyed it and that I helped you.