This comment was posted to reddit on Aug 21, 2017 at 9:40 am and was deleted within 8 minutes.

Python 3; tried going for a more efficient solution (I'm not sure how good it is compared to /u/-P-e-t-e-r- 's solution. Also, I started using Python yesterday, so any improvements would be great.

```
def isLatinSquare(dict_pos):
for ipos in dict_pos.keys():
pos = dict_pos[ipos]
for icount in pos[0].keys():
count = pos[0][icount]
if count > 1:
return False
for icount in pos[1].keys():
count = pos[0][icount]
if count > 1:
return False
return True
#get input
print("Enter the length of the array.")
n = int(input())
print("Enter the array.")
array_inputted = input().split()
#store positions
dict_pos = {}
for i in range(n*n):
num = array_inputted[i]
x, y = divmod(i, n)
if num in dict_pos:
dict_pos[num][0][y] = dict_pos[num][0].get(y, 0) + 1
dict_pos[num][1][x] = dict_pos[num][1].get(x, 0) + 1
else:
dict_pos[num] = [{y:1}, {x:1}]
#print(f"dp[{num}][x][{y}]={dict_pos[num][0][y]}; dp[{num}][y][{x}]={dict_pos[num][1][x]}")
#evaluate
result = isLatinSquare(dict_pos)
print(result)
```