How to convert a given 3x3 matrix into a magic square. Learn how magic squares work and how many there are. Problem source on hackerrank: www.hackerrank... This video is part of my coding interview questions series.
I would say that both solutions are valid. I just wanted to present an approach that gives some thinking to the math of the problem before coding. This approach often leads to more efficient algorithms. To have less hardcoding at the end, one could also calculate the other magic squares from one given magic square by writing functions that rotate and mirror the given one.
Hi... after to wiew this great tutorial... maybe to view other video can you to download Excel file to resolve Square Magic 3x3 and 5x5. To Find on RU-vid as: Creación Cuadrado Mágico lado impar - Creating Magic Square odd side. Grettings.
great thinking, but how are we going to handle this once we have a 5x5 square or even more? shouldn't be a better way than defining all the possible magic squares and comparing them.
@@quiped7719 it's possible to have 5x5 if you're not constrained by numbers from 1 to 9 only, that's for 5x5 and numbers 1 to 25, the magic constant should be 5 * ( 25+1)/2 = 65. and you will have to generate combinations and all magic squares like done in the video Imagine trying to do that in 45 min coding assessment while there's another problem waiting to be solved.