The idea is not to check every element in right and left diagonal instead use property of diagonals: 1.The sum of i and j is constant and unique for each right diagonal where i